gpt4 book ai didi

jsf - 如何调用 p :commandButton in the error page shown by FullAjaxExceptionHandler?

转载 作者:行者123 更新时间:2023-12-01 12:47:55 25 4
gpt4 key购买 nike

我正在使用 OmniFaces FullAjaxExceptionHandler和 PrimeFaces。我在 errorPage.xhtml 中添加了一个命令按钮,如下所示:

<h:form>
<p:commandButton id="logoutButtonId" value="Redirect" actionListener="#{userMB.logout()}">
</h:form>

错误页面正确显示,但按钮未触发方法 #{userMB.logout()}。这是我所了解的我的设置中发生的事情:

  1. 如果发生错误,FullAjaxExceptionHandler 会很好地显示 errorPage.xhtml
  2. 如果我点击我添加的按钮,页面会更新相同的数据,就像发生刷新一样。
  3. 如果我再次单击该按钮,则会触发托管 bean 方法。

只有在第二次单击时才会调用 bean 方法。似乎在第一次加载时,bean 方法没有绑定(bind)到对象。

在使用 FullAjaxExceptionHandler 时,如何在错误页面中添加一个命令按钮,并将 Action / Action 监听器正确绑定(bind)到 HTML 组件?

最佳答案

这就是对我有用的方法,结合了 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);
}
};

关于jsf - 如何调用 p :commandButton in the error page shown by FullAjaxExceptionHandler?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14272835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com