JSF - Richfaces - How to find out if a session is expiring (on the client)

I am developing an application using JSF-richfaces.

The application has a standard login page, session management and session expiration time is 15 minutes.

One of the requirements is that when the session expires, and if the user clicks on any of the links, I need to display a pop-up window (instead of going to the login page), which will indicate that "your session has expired, please log in again ",.

If this is the only link, I can use a4j to check if the session has expired or not. But in my case, I need to display a β€œsession out” warning for each link and button.

Any pointers to this will help me move forward.

Thanks in advance.

+3
source share
3 answers

If the session timeout is 15 minutes, you can simply set up a Javascript call (using the method setTimeout) that will display a popup. If the user clicks on one link, the Javascript call will be dropped, so the pop-up will only be displayed if the user remains on the same page for at least 15 minutes.

You can try something like this:

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

Explanations:

Javascript- <a4j:outputPanel>, ajaxRendered, true. , - Javascript , Ajax. - 15 (900000 ), .

( modalPanel) , Facelets. ...

+4

RichFaces Timeouts (ViewExpiredException) .

web.xml:

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

, javascript :

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

Richfaces ( ), JS, .

Richfaces

+1

Source: https://habr.com/ru/post/1714668/


All Articles