对错误页面错误报告表 [英] Bug report form on error page

查看:120
本文介绍了对错误页面错误报告表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JBoss的7.1和RichFaces的4.1 JSF的Web应用程序。我试图配置web.xml中的自定义错误页,但遇到了问题,这并不为AJAX请求工作。作为一个解决方案,我试图用 Omnifaces FullAjaxExceptionHandler 其中显示错误页面就好了。

I have a JSF web application in JBoss 7.1 and Richfaces 4.1. I tried to configure a custom error page in web.xml but came across the problem, that this does not work for AJAX requests. As a solution I tried to use Omnifaces FullAjaxExceptionHandler which displays the error page fine.

不过,我想增加一个表单,允许用户输入更多的信息,并将其发送,随着例外,因为电子邮件给我。问题是,该错误页面上,在提交按钮不起作用。当我点击它的错误页面只是重新加载。在接下来单击一切工作正常。

However I wanted to add a form that allows the user to enter additional information and send this, along with the exception, as an email to me. The problem is that on the error page, the submit buttons does not work. When I click on it the error page just reloaded. On the next click everything works as expected.

,同样的问题会发生,且h:commandlinks在一个小的菜单,它是错误的页面模板中

The same problem occurs with h:commandlinks in a small menu that is in the template of the error page.

我是很新的JSF,所以我真的不知道为什么会这样,以及它如何可以固定。还是有更好的方法来做到这一点?

I'm quite new to JSF so I don't really know why this happens and how it can be fixed. Or is there a better way to accomplish this?

推荐答案

这是关系到 JSF规范问题790 这归结于阿贾克斯,更新某些成分又包含一个或多个< H:形式GT; 组件不正确地更新新这些形式的视图状态标识。

This is related to JSF spec issue 790 which boils down to that ajax-updating some component which in turn contains one or more <h:form> components doesn't properly update the new view state identifier of those forms.

此问题被固定在即将到来的JSF 2.2,但在那之前,你已经做下面的基于JavaScript的解决方法。

This issue is fixed in the upcoming JSF 2.2, but until then you've to do with the following JavaScript based workaround.

jsf.ajax.addOnEvent(function(data) {
    if (data.status == "success") {
        var viewState = getViewState(data.responseXML);

        if (viewState) {
            for (var i = 0; i < document.forms.length; i++) {
                var form = document.forms[i];

                if (!hasViewState(form)) {
                    createViewState(form, viewState);
                }
            }
        }
    }
});

function getViewState(responseXML) {
    var updates = responseXML.getElementsByTagName("update");

    for (var i = 0; i < updates.length; i++) {
        var update = updates[i];

        if (update.getAttribute("id") == "javax.faces.ViewState") {
            return update.firstChild.nodeValue;
        }
    }

    return null;
}

function hasViewState(form) {
    for (var i = 0; i < form.elements.length; i++) {
        if (form.elements[i].name == "javax.faces.ViewState") {
            return true;
        }
    }

    return false;
}

function createViewState(form, viewState) {
    var hidden;

    try {
        hidden = document.createElement("<input name='javax.faces.ViewState'>"); // IE6-8.
    } catch(e) {
        hidden = document.createElement("input");
        hidden.setAttribute("name", "javax.faces.ViewState");
    }

    hidden.setAttribute("type", "hidden");
    hidden.setAttribute("value", viewState);
    hidden.setAttribute("autocomplete", "off");
    form.appendChild(hidden);
}

只是把它作为&LT; H:outputScript名=some.js目标=头&GT; &LT; H :身体GT; 的错误页面。如果你不能保证该页面使用JSF &LT; F:AJAX&GT; ,那么你可能需要增加一个额外的如果(typeof运算JSF! =='不确定') jsf.ajax.addOnEvent检查()电话。

Just include it as <h:outputScript name="some.js" target="head"> inside the <h:body> of the error page. If you can't guarantee that the page uses JSF <f:ajax>, then you might want to add an additional if (typeof jsf !== 'undefined') check before jsf.ajax.addOnEvent() call.

的JSF组件库PrimeFaces已经在其核心Ajax引擎已经解决了这个问题,所以如果你已经使用它,你可能要全部更换&LT; F:AJAX&GT; 链接/由PrimeFaces那些按钮。

The JSF component library PrimeFaces has already solved this issue in its core ajax engine, so if you happen to use it already, you might want to replace all <f:ajax> links/buttons by the PrimeFaces ones.

  • <一个href="http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichContainsAnotherForm"相对=nofollow>在JSF 2.0通信 - 内容的Ajax渲染包含另一种形式

这篇关于对错误页面错误报告表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆