Search code examples
javanavigationelsession-timeoutjsf-2

JSF2: Using EL in navigation rules. Redirect on timeout?


I am wondering the following:

When a request comes into the JSF servlet, is it possible to redirect to a session timeout page if a session bean indicates that the session has not been logged in?

For example:

<navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
        <if>#{not userBean.loggedIn}</if>
        <to-view-id>/login.jsf</to-view-id>
        <redirect/>
    </navigation-case>
</navigation-rule>

Obviously it would need to exclude the login.jsf from this rule...but you get the point. I have tried something similar and it does not appear to work, and even if it did, how would it deal with Bookmarked URLS?

How best to implement this in JSF2? Also, is there anything like the global.asax from ASP.NET in JSF2, or are PhaseListeners/Filters about it?

Thank you.


Solution

  • Navigation rules would not be a good place for this sort of functionality since the NavigationHandler is not invoked until quite late in the lifecycle (Invoke Application).

    alt text
    (source: ibm.com)


    You can use declarative security (in the web.xml) to redirect to a login page. Alternatively, you can redirecting using a Filter if you want finer grain control over what happens.