I've been using the JSF 1.2 with the ViewHandler described in this answer : IceFaces Session Expiry causes an exception it was very useful because when the exception occurs the page is automatically regenerated, good for public pages. The problem is that it is not compatible with JSF 2.0. Does anybody have an idea how to make it work in JSF 2.0 or a replacement?
Edit :
I've found this solution : Stateless JSF, but still wondering if there is any way to do it by a ViewHandler
like I was doing in JSF 1.2. Here is my JSF 2.0 current code :
public class AutoRegeneratorViewHandler extends GlobalResourcesViewHandler
{
public AutoRegeneratorViewHandler(ViewHandler viewHandler)
{
super(viewHandler);
}
@Override
public UIViewRoot restoreView(FacesContext p_oContext, String p_sViewID)
{
UIViewRoot oViewRoot = super.restoreView(p_oContext,p_sViewID);
try
{
if(oViewRoot == null)
{
initView(p_oContext);
oViewRoot = createView(p_oContext,p_sViewID);
p_oContext.setViewRoot(oViewRoot);
try
{
renderView(p_oContext,oViewRoot);
}
catch(IOException e)
{
e.printStackTrace();
}
System.out.println("Created : " + p_sViewID);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return oViewRoot;
}
}
This code get rid of the ViewExpiredException
but when the page is loaded, I'm appearing not logged.
Test case :
- Open the website
- Wait more than the current session expiration time (from
web.xml
) - Enter username/password
- Hit Login button
- Page reload with the login form empty
- Reload the page
- Page show Welcome and login form is not shown (expected behavior)