JSF'de h:form elementi ile eklediğiniz formda , action değeri /sayfa_pathi şeklinde olmaktadır. Bunun yerine action ifadesini http://sizindomain/sayfapathi şeklinde değiştirebilmeniz mümkündür.
Örneğin www.example.com sitemizde /kayit/index.jsf sayfası olsun. Bu sayfanın formunun action'nda /kayit/index.jsf olacaktır. Bunun nedeni JSF framework'üdür. action ifadesinde http://www.example.com/kayit/index.jsf gözükmesini sağlayalım. Bunun için aşağıdaki ViewHandlerWrapper den türemiş bir sınıf eklemek gerekir :
package com.fibiler.test;
import javax.faces.application.*;
import javax.faces.context.*;
import javax.servlet.http.*;
public class CustomViewHandler extends ViewHandlerWrapper{
private ViewHandler wrappped;
public CustomViewHandler(ViewHandler wrappped) {
super();
this.wrappped = wrappped;
}
@Override
public ViewHandler getWrapped() {
return wrappped;
}
@Override
public String getActionURL(FacesContext context, String viewId) {
HttpServletRequest request=(HttpServletRequest)FacesContext.
getCurrentInstance().getExternalContext().getRequest();
String url=request.getRequestURL().toString();
if(url==null){
return super.getActionURL(context, viewId);
}
return "http://www.example.com"+super.getActionURL(context, viewId);
}
}
Yukarıdaki kodda getActionURL method'u override edilmiş ve action URL'inin başına http://www.example.com eklenmiştir.
CustomViewHandler sınıfı tanımı faces-config.xml dosyasına aşağıdaki gibi eklenmelidir:
<application>
<view-handler>com.fibiler.test.CustomViewHandler</view-handler>
</application>
Bu işlemleri yaptıktan sonra /kayit/index.jsf sayfasına girip form elementinin action değerini kontrol ettiğinizde http://www.example.com//kayit/index.jsf değerini görmeniz gerekir.