Question

I am using Glassfish security with Realm for my J2ee project using jsf . My session time out in 30 min.

when i click on component it is redirecting to the login page thats good.

but u want before that the user click on the component when the session is out a dialog or msg need to apear to alarm user that the session is expired .

thats why i tried this way but didnt work using jsf listener :

<f:event listener="#{Logincontroller.checksessiontimeout}" type="preRenderView"/>

and in the managed been :

public void checksessiontimeout(ComponentSystemEvent event) 
    {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest)             context.getExternalContext().getRequest();
        if (request.getRequestedSessionId()!=null && !request.isRequestedSessionIdValid())
        { 
            System.out.println("Session Log OUT");
        }
    }

but when the session is time out didnt print nothing for me thats prove the function didnt work .

Was it helpful?

Solution

If you can't use OmniFaces, how about using an idleMonitor to check the session status every x milliseconds? The below will fire when the user comes back to the web page after being away for 5 minutes. The only problem is it won't fire if the user sits there moving the mouse around the web page without actually doing anything, but the session would still timeout.

<p:idleMonitor timeout="18000000">
<p:ajax event="active" listener="#{Logincontroller.checksessiontimeout}" />
</p:idleMonitor>

OTHER TIPS

If you want to show an error message to the user, I suggest you do this with javascript. I think that System.out.println will just print a line to your Glassfish's console.

Try putting this as error message:

out.print("<script>alert(\"Session timed out!\");</script>");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top