javajsfviewexpiredexception

Enforce javax.faces.application.ViewExpiredException for testing application


I would like to test my webapplication (JSF 2.2) which has a custom Esxception Handler Factory. Now i would like to know if everything works as expected when a javax.faces.application.ViewExpiredException is thrown. Is there any way, I can decrease the time to wait for getting this exception? Throwing it programmatically is not an option, as I would like to have a nearly 100% productive test scenario.


Solution

  • As far as I'm concerned, it should be enough to force a Session expiration while you keep the JSF view state in the server side:

    Setting STATE_SAVING_METHOD to client has however an additional functional advantage: it prevents ViewExpiredExceptions when the session has expired or when the client opens too many views.

    So, being the javax.faces.STATE_SAVING_METHOD defaulted to server, you only need to specify the timeout you want for the Http Session:

    <session-config>
        <session-timeout>2</session-timeout>
    </session-config>
    

    As an alternative, you could choose to set your own limit of views. That depends on the concrete JSF implementation, Mojarra defaults to 16 and MyFaces to 20. For the first one, you could use com.sun.faces.numberOfLogicalViews to decrease the amount of views accepted simultaneously per client. As an example, setting it to 3 should fire the exception when you've got four tabs opened in the same browser (same Http Session).

    See also: