我正在使用OmniFaces FullAjaxExceptionHandler
和PrimeFaces。我在errorPage.xhtml
中添加了一个命令按钮,如下所示:
<h:form>
<p:commandButton id="logoutButtonId" value="Redirect" actionListener="#{userMB.logout()}">
</h:form>
错误页面显示正确,但该按钮不会触发方法#{userMB.logout()}
。
这就是我理解在我的设置中发生的事情:
FullAjaxExceptionHandler
会很好地显示errorPage.xhtml
。只有在第二次单击时才会调用bean方法。似乎在第一次加载时,bean方法不会绑定到对象。
如何在错误页面中添加命令按钮,并在使用FullAjaxExceptionHandler
时将action / actionlistener正确绑定到HTML组件?
答案 0 :(得分:2)
这对我有用,这是BalusC在下面的回答中提到的方法的组合。它适用于IE和Firefox。在某些情况下可能需要进行一些调整,但由于错误页面只有一个表单,所以我没有费心通过表单循环。
var originalPrimeFacesAjaxResponseFunction = PrimeFaces.ajax.AjaxResponse;
PrimeFaces.ajax.AjaxResponse = function(responseXML) {
var newViewRoot = $(responseXML.documentElement).find("update[id='javax.faces.ViewRoot']").text();
if (newViewRoot) {
var viewState = $(responseXML.documentElement).find("update[id='javax.faces.ViewState']").text();
$('head').html(newViewRoot.substring(newViewRoot.indexOf("<head>") + 6, newViewRoot.indexOf("</head>")));
$('body').html(newViewRoot.substring(newViewRoot.indexOf("<body>") + 6, newViewRoot.indexOf("</body>")));
if (!$('input').attr("javax.faces.ViewState")){
var hidden = document.createElement("input");
hidden.setAttribute("type", "hidden");
hidden.setAttribute("name", "javax.faces.ViewState");
hidden.setAttribute("value", viewState);
hidden.setAttribute("autocomplete", "off");
$('form').append(hidden);
}
} else {
originalPrimeFacesAjaxResponseFunction.apply(this, arguments);
}
};
答案 1 :(得分:0)
此问题有两个可能的原因:
如果您使用的是Internet Explorer,则可以将其识别为PrimeFaces @all
,以便无法在基于IE的浏览器中初始化必要的ajax javascripts。这在这里得到解答:Object doesn't support this property or method with primefaces omnifaces timeout combination。
如果您正在使用其他浏览器并且使用JSF标准<f:ajax>
来触发ajax操作,则可以将其识别为JSF自己的jsf.js
以无法更新JSF视图状态在@all
之后的所有形式。这在这里得到解答:Bug report form on error page。
请注意,这些脚本需要放在调用ajax操作的页面上,而不是放在错误页面本身上。