无法使用 JSF2 捕获 RichFaces 4 a4j:commandButton 的会话超时错误
Not able to capture the session timeout error for RichFaces 4 a4j:commandButton with JSF2
我在我的 xhtml page.It 中使用了 a4j:commandButton,工作正常。但是在会话超时之后,我可以单击按钮,但它不会触发支持 bean 操作方法。我想向用户显示会话已过期。我关注了 richfaces 站点中的 material,但不知道为什么它不起作用。我将会话超时设置为 1 分钟以测试场景。
web.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>
<param-value>true</param-value>
</context-param>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
Javascript:
<h:head>
<!-- (...) -->
<script type="text/javascript">
A4J.AJAX.onError = function(req, status, message){
window.alert("Custom onError handler "+message);
}
</script>
</h:head>
xhtml:
<a4j:commandButton id="submitButton"
value="Remediate Data"
action="#{addressManagedBean.submit}"
onclick="return confirm('Are You Sure?')"
styleClass="button-style" render="successMessage failureMessage infoMessage validationTMPMessage validationBOMessage">
</a4j:commandButton>
<a4j:log></a4j:log>
日志:
info [01:16:08.428]: Received 'begin' event from <input id=form12:submitButton class=button-style ...>
info [01:16:08.740]: Received 'beforedomupdate' event from <input id=form12:submitButton class=button-style ...>
info [01:16:08.740]: Element error
<error><error-name>class javax.faces.application.ViewExpiredException</error-name><error-message><![CDATA[viewId:/remediateData.xhtml - View /remediateData.xhtml could not be restored.]]></error-message></error>
error[01:16:08.740]: Received 'error@serverError' event from <input id=form12:submitButton class=button-style ...>
error[01:16:08.740]: [200] class javax.faces.application.ViewExpiredException: viewId:/remediateData.xhtml - View /remediateData.xhtml could not be restored.
info [01:16:08.740]: Received 'complete' event from <input id=form12:submitButton class=button-style ...>
我怎样才能实现我的目标?
这适用于 JSF 2.1.28
<h:body>
<script language="javascript">
jsf.ajax.addOnError(function(data) {
alert('Error');
});
</script>
[...]
我已将脚本放在正文部分。
此问题已解决。我使用了 jsf onError 和 onEvent javascript 方法。
http://javaevangelist.blogspot.in/2014/01/jsf-2x-tip-of-day-custom-jsf-ajax-error.html
我在我的 xhtml page.It 中使用了 a4j:commandButton,工作正常。但是在会话超时之后,我可以单击按钮,但它不会触发支持 bean 操作方法。我想向用户显示会话已过期。我关注了 richfaces 站点中的 material,但不知道为什么它不起作用。我将会话超时设置为 1 分钟以测试场景。
web.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>
<param-value>true</param-value>
</context-param>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
Javascript:
<h:head>
<!-- (...) -->
<script type="text/javascript">
A4J.AJAX.onError = function(req, status, message){
window.alert("Custom onError handler "+message);
}
</script>
</h:head>
xhtml:
<a4j:commandButton id="submitButton"
value="Remediate Data"
action="#{addressManagedBean.submit}"
onclick="return confirm('Are You Sure?')"
styleClass="button-style" render="successMessage failureMessage infoMessage validationTMPMessage validationBOMessage">
</a4j:commandButton>
<a4j:log></a4j:log>
日志:
info [01:16:08.428]: Received 'begin' event from <input id=form12:submitButton class=button-style ...>
info [01:16:08.740]: Received 'beforedomupdate' event from <input id=form12:submitButton class=button-style ...>
info [01:16:08.740]: Element error
<error><error-name>class javax.faces.application.ViewExpiredException</error-name><error-message><![CDATA[viewId:/remediateData.xhtml - View /remediateData.xhtml could not be restored.]]></error-message></error>
error[01:16:08.740]: Received 'error@serverError' event from <input id=form12:submitButton class=button-style ...>
error[01:16:08.740]: [200] class javax.faces.application.ViewExpiredException: viewId:/remediateData.xhtml - View /remediateData.xhtml could not be restored.
info [01:16:08.740]: Received 'complete' event from <input id=form12:submitButton class=button-style ...>
我怎样才能实现我的目标?
这适用于 JSF 2.1.28
<h:body>
<script language="javascript">
jsf.ajax.addOnError(function(data) {
alert('Error');
});
</script>
[...]
我已将脚本放在正文部分。
此问题已解决。我使用了 jsf onError 和 onEvent javascript 方法。
http://javaevangelist.blogspot.in/2014/01/jsf-2x-tip-of-day-custom-jsf-ajax-error.html