views:

3123

answers:

3

I am developing application using JSF- richfaces.

The application has standard login page, session management and the session expire time is 15 min.

One of the requirement is, when the session expires and if the user clicks on any of the links, I need to display a popup(instead of going to login page) which will say "Your session expired, please login again".

If it is a single link I can use a4j to check if the session is expired or not. But in my case, I need to display the "session out" alert for every link and button.

Any pointers to this will help me to proceed forward.

Thank you in advance.

+4  A: 

If the session timeout is 15 minutes, you can simply set a Javascript call (using setTimeout method) that will display a popup. If the user click on one link, the Javascript call will be resetted, so the popup will only be shown if the user stays one the same page for at least 15 minutes.

You can try with something like that:

<a4j:outputPanel ajaxRendered="true">
    <script type="text/javascript">
        setTimeout("Richfaces.showModalPanel('xxx');", 900000);
    </script>
</a4j:outputPanel>

Explanations:

We wrap the Javascript code in a <a4j:outputPanel> component that has a ajaxRendered attribute set to true. This way, the Javascript timeout will be resetted even when the user clicks on a Ajax link. Then, we set a timeout to 15 minutes (900000 milliseconds then) until a modalpanel is displayed.

I suggest that you put this code (and the modalPanel also) in a template if you use Facelets. This template will then be used for every page of your application...

romaintaz
Thanks for the answer.This solves my problem to 50%Other thing I want to implement, I want to know if the session is valid when user clicks on some button or link.How can I bind the button/ link clicks to some javascript actions?
Vineyard
+1  A: 

Richfaces can handle session expiration (and other errors) by defining your own JS function, which is executed at the moment the situation occurance.

Richfaces guide

MarrLiss
+1  A: 

Hi

RichFaces provides an additional way to catch Timeouts (ViewExpiredException) on client side.

First, add the following code in your web.xml:

    <context-param>
    <param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>
    <param-value>true</param-value>
</context-param>

Finally, add some javascript on the page:

<script type="text/javascript">
//<![CDATA[
A4J.AJAX.onError = function(req, status, message) {
 *window.location.reload();*
}
//]]>
</script>
FG

related questions