2 Replies Latest reply on Jan 21, 2007 11:13 AM by weidong jin

    one question about Interceptor

    weidong jin Newbie

      When I run example "icefaces",I debug class LoggedInInterceptor.But I
      found :

       Method method = invocation.getMethod();
       if ( method.getReturnType().equals(void.class) )
       {
       return null;
       }
      

      Why "return null" not "return 'login'".I clicked link "http://localhost:8000/seam-registration/main.seam?cid=2" ,it did not return to "login" page.So I fixed "retrun null" above to "return 'login'",but it still did not return to "login" page.Through logging, I found if "Lifecycle.getPhaseId()!=PhaseId.INVOKE_APPLICATION",it will never be redirect to new page.How can I redirect to new page in Interceptor,and who can tell me how does Interceptor work?
      Your appreciation!

        • 1. Re: one question about Interceptor
          Norman Richards Master

          You can't change the return type of a Java method. If the method doesn't return a value then you can't suddenly decide to return a string in an interceptor.

          • 2. Re: one question about Interceptor
            weidong jin Newbie

            You probably misunderstand.
            The comlete code is here:

            import javax.faces.event.PhaseId;
            
            import org.jboss.seam.annotations.Interceptor;
            import org.jboss.seam.contexts.Contexts;
            import org.jboss.seam.contexts.Lifecycle;
            import org.jboss.seam.interceptors.BijectionInterceptor;
            import org.jboss.seam.interceptors.BusinessProcessInterceptor;
            import org.jboss.seam.interceptors.ConversationInterceptor;
            import org.jboss.seam.interceptors.RemoveInterceptor;
            import org.jboss.seam.interceptors.ValidationInterceptor;
            
            @Interceptor(around={BijectionInterceptor.class, ValidationInterceptor.class,
             ConversationInterceptor.class, BusinessProcessInterceptor.class},
             within=RemoveInterceptor.class)
            public class LoggedInInterceptor
            {
            
             @AroundInvoke
             public Object checkLoggedIn(InvocationContext invocation) throws Exception
             {
             boolean isLoggedIn = Contexts.getSessionContext().get("loggedIn")!=null;
             if ( Lifecycle.getPhaseId()==PhaseId.INVOKE_APPLICATION )
             {
             if (isLoggedIn)
             {
             return invocation.proceed();
             }
             else
             {
             return "login";
             }
             }
             else
             {
             if ( isLoggedIn )
             {
             return invocation.proceed();
             }
             else
             {
             Method method = invocation.getMethod();
             if ( method.getReturnType().equals(void.class) )
             {
             return null;
             }
             else
             {
             return method.invoke( invocation.getTarget(), invocation.getParameters() );
             }
             }
             }
             }
            
            }