Controlling the session expiration

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!

Tip

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.

Tip

Session expiration time

Tip

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.

Note

This feature doesn't work if you are using MyFaces, unless you disable its error handling, in this way:

<context-param> <param-name>org.apache.myfaces.ERROR_HANDLING</param-name> <param-value>false</param-value> </context-param>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.200.206