5 Replies Latest reply on Jun 23, 2009 6:19 PM by pramod_bs

    ViewExpiredException - conditional redirect

    pramod_bs

      I have a requirement to handle ViewExpiredException based on the url context.
      Ex: When the application View Expires while accessing the pages
      1. http://localhost/applicationname should redirect the ViewExpriedException to say

      <redirect view-id="/viewerror.xhtml>



      2. http://localhost/applicationname/admin  should redirect the ViewExpriedException to say

      <redirect view-id="/admin/viewerror.xhtml"> 



      I am not sure how I can configure this in pages.xml. Hope I explained the rLPequirement properly for others to understand. PLEASE HELP


        • 1. Re: ViewExpiredException - conditional redirect
          billevans

          That's funny!!   I want to do exactly the same thing!!  


          I will post the answer here if I find out before you!

          • 2. Re: ViewExpiredException - conditional redirect
            billevans

            By the way, I did try following the advice in section 6.7 of the Seam reference guide:



            6.7. Fine-grained files for definition of navigation, page
            actions and parameters
            If you have a lot of different page actions and page parameters, or even just a lot of navigation
            rules, you will almost certainly want to split the declarations up over multiple files. You can define
            actions and parameters for a page with the view id /calc/calculator.jsp in a resource named
            calc/calculator.page.xml.

            ... but it didn't work...  :(

            • 3. Re: ViewExpiredException - conditional redirect
              billevans

              Here's a way to do it:


              In pages.xml:
                
                 <exception class="javax.faces.application.ViewExpiredException">         
                       <redirect view-id="#{facesContext.externalContext.requestServletPath}">
                          <message severity="INFO">Your session has timed out, please log in again</message>
                      </redirect>
                  </exception>


              And for each of your pages:


                  <page view-id="/main/main.xhtml" login-required="true">
                       <action execute="#{exceptionHandler.redirectOnViewExpired}"/>
                  </page>  


              Where exceptionHandler is the name of an application-scoped class:

                   @Name("exceptionHandler")
                   @Scope(ScopeType.APPLICATION)
                   @Startup
                   public class ExceptionHandler {
                   //
                   @In(value="org.jboss.seam.handledException", required=false) private Exception exception;
                   @In private Redirect redirect;     
                   
                   public void redirectOnViewExpired() {
                        if (this.exception != null &&
                           (exception instanceof ViewExpiredException
              exception instanceof NotLoggedInException)) {
                             //
                             String currentViewId = FacesContext.getCurrentInstance().getExternalContext().getRequestServletPath();
                             if (currentViewId.endsWith("blahblah.seam"))
                                  redirect.setViewId("/expired.xhtml");               
                             else {
                                  redirect.setViewId("/login.xhtml");
                             }
                             redirect.execute();
                        }
                   }
                  }


              Hope this helps.

              • 4. Re: ViewExpiredException - conditional redirect
                billevans

                Whoops!! Sorry about the formatting... you should be able to dissect the solution though!

                • 5. Re: ViewExpiredException - conditional redirect
                  pramod_bs

                  Thanks for your input. Don't you think we should have something like:


                   <exception class="javax.faces.application.ViewExpiredException">
                          <navigation  from-view-id="/*.xhtml"> 
                            <redirect view-id="/home.xhtml">
                                        <message severity="warn">Your session has timed out, please try again</message>
                               </redirect>
                          </navigation>        
                  
                        <navigation  from-view-id="/admin/*.xhtml"> 
                            <redirect view-id="/home.xhtml">
                                        <message severity="warn">Your session has timed out, please try again</message>
                               </redirect>
                          </navigation> 
                  
                   </exception>
                  
                  



                  SEAM GURUS.. Does this makes sense.