Using the RichFaces framework, it is possible to control the session expiration during an Ajax request in a better way just redefine the A4J.AJAX.onExpired
JavaScript method!
You can keep the session alive by polling the server at a regular interval of time, by using the a4j:poll
component (we have seen how to use it in this chapter).
Let's do an example using a modal panel to notify that the session expired open the /view/layout/template.xhtml
file and move at the end of it, just before the</body>
tag.
Let's add the modal panel code first:
<rich:modalPanel id="sessionExpiredMP" resizeable="false" width="300" height="200"> <h:outputText value="The session has expired" /> <br/> <s:button value="Click here to close it" onclick="#{rich:component('sessionExpiredMP')}.hide();" /> </rich:modalPanel>
This modal panel will be opened when the session will expire.
For doing that, let's redefine the JavaScript function A4J.AJAX.onExpired
after the modal panel code, let's add the following:
<script type="text/javascript"> A4J.AJAX.onExpired = function(loc, expiredMsg) { $('sessionExpiredMP').show(); }; </script>
Now every time the session will expire, the modal panel will be opened.
It is possible to redefine also the onError
JavaScript error handler.
In order to control the session expiration time, it is possible to set the session-timeout
option into the web.xml
file. If you don't find it, just put the following code:
<session-config> <session-timeout>10</session-timeout> </session-config>
Where 10
means that the session will expire after 10 minutes of inactivity.
18.222.20.20