0

I have used a a4j:commandButton in my xhtml page.It is working fine. But after session-timeout I can click the button but it doesn't hit the backing bean action method. I want to show the user that the session has expired. I have followed the material in richfaces site but don't know why it isn't working. I have kept session timeout as 1 minute to test the scenario.

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>

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 ...>

How can I achieve my goal?

Emil Sierżęga
  • 1,785
  • 2
  • 31
  • 38
  • It looks like docs are out of date (your solution is for RF 3). Check this http://stackoverflow.com/questions/11203195/session-timeout-and-viewexpiredexception-handling-on-jsf-primefaces-ajax-request – Paszek Sep 08 '15 at 07:11

2 Answers2

0

This works fine with JSF 2.1.28

<h:body>
<script language="javascript">
    jsf.ajax.addOnError(function(data) {
         alert('Error');
    });
</script>

[...]

I have places my script in the body section.

Kai B.
  • 48
  • 5
0

This issue is fixed. I have used jsf onError and onEvent javascript method.

http://javaevangelist.blogspot.in/2014/01/jsf-2x-tip-of-day-custom-jsf-ajax-error.html