//<![CDATA[
document.forms[0].setAttribute("action",location.href);
package Application;
import javax.faces.application.ViewHandler;
public class MyHandler extends ViewHandler {
// 保存默认自带的ViewHandler
private ViewHandler defaultHandler;
public MyHandler(ViewHandler handler) {
this.defaultHandler = handler;
}
public String getActionURL(FacesContext context, String viewId) {
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
// 取参数列表
String qStr = request.getQueryString();
// 取系统自己生成的url
String qOldUrl = this.defaultHandler.getActionURL(context,viewId);;
if(qStr == null){
return qOldUrl;
}else{
return qOldUrl + "?" + qStr;
}
}
}
然后修改faces-config.xml文件,加上viewhandle的配置
<faces-config>
<application>
<view-handler>Application.MyHandler</view-handler>
</application>
</faces-config>
注:viewhandler中的getActionURL方法就是返回表单的action属性,所以只重写了viewhandler中的方法,其他viewhandler的虚方法也需要重写