开发者

JSF 2.0 ViewExpiredException

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();
        }

      开发者_如何学Python  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)


I think the JSF2 way is to provide your own exception handler.

In the exception handler, one can loop all unhandled exceptions, check for the ViewExpiredException, and remove it.

One an even populate the request params and navigate to a specific facelet, which can render the correct and informative page that makes use of those request params that are populated from the exception handler. Can even navigate to the login screen if you want.

Here's a such article describing how to implement it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜