1 Reply Latest reply on Jun 14, 2008 3:52 AM by Dan Allen

    Customizing redirect.captureCurrentView in case of errors

    infinity2heaven Novice

      I'm using Seam's authentication with a redirect view filter,  it works perfectly fine.


      components.xml


      
      <event type="org.jboss.seam.security.notLoggedIn">
      
         <action execute="#{redirect.captureCurrentView}"/>
      
      </event>
      
      
      <event type="org.jboss.seam.security.postAuthenticate">
      
         <action execute="#{redirect.returnToCapturedView}"/>
      
      </event>
      
      



      However, I have a problem, when a redirect should occur to a specified page, in case of recoverable exceptions/errors. For ex,


      pages.xml



      
      ....
      
      ....
      
      <exception class="org.jboss.seam.security.NotLoggedInException">
      
           <redirect view-id="/login.xhtml">
      
               <message severity="INFO">You must be logged in to perform this action</message>
      
           </redirect>
      
        </exception>
      
        
      
        <exception class="org.jboss.seam.security.AuthorizationException">
      
          <redirect>
      
            <message severity="INFO">You don't have permission to do this</message>
      
          </redirect>
      
        </exception>
      
         
      
        <exception class="org.jboss.seam.framework.EntityNotFoundException">
      
          <redirect view-id="/error.xhtml">
      
            <message severity="ERROR">Not found</message>
      
          </redirect>
      
        </exception>
      
        
      
        <exception class="javax.persistence.OptimisticLockException">
      
          <end-conversation/>
      
          <redirect view-id="/error.xhtml">
      
            <message severity="ERROR">Another user changed the same data, please try again</message>
      
          </redirect>
      
        </exception>
      
        
      
        <exception class="javax.faces.application.ViewExpiredException">
      
            <redirect view-id="/error.xhtml">
      
                <message severity="ERROR">Your session has timed out, please login again</message>
      
            </redirect>
      
        </exception>
      
        
      
        <exception class="java.lang.Exception">
      
          <end-conversation/>
      
          <redirect view-id="/error.xhtml">
      
            <message severity="ERROR">An Application Error has occurred</message>
      
          </redirect>
      
        </exception>
      
      



      So, if you have encounter a session timeout, user is redirected to an error page simply puts a message to log back in. the url opens a login page and after successful login -- takes it back to the error page! (because captureCurrentView returns the previous error.xhtml).


      My question is -- How do  I override this rule in components.xml (in my case, whenever the captureCurrentView =/error.xhtml, I need to redirect to home.xhtml)

        • 1. Re: Customizing redirect.captureCurrentView in case of errors
          Dan Allen Master

          All you need to do is register your own method-binding expression rather than #{redirect.returnToCapturedView}. You can inject the redirect component into your custom component, check for /error.xhtml and return a different value instead. Actually, your best bet is to extend org.jboss.seam.faces.Redirect and override the execute() method. You will need to register your own component using the component name org.jboss.seam.faces.redirect.