6 Replies Latest reply on Jun 14, 2012 1:26 PM by lightguard

    Seam 3 exception handler - redirection doesn't work

    pseudoem

      Hi, I'm not entirely sure if this is the right place to ask (so I'm sorry if it isn't), but..

      What can be cause of not working redirection in this case?

      @HandlesExceptions
      public class ExceptionHandler {
         
      public void handleException(@Handles CaughtException<Throwable> e,
                                     
      Messages messages     
                                     
      FacesContext facesContext){

              messages
      .error("something went wrong");
              facesContext
      .getApplication().getNavigationHandler()   
                     
      .handleNavigation(facesContext, null, "errorpage");
         
      }
      }

      Handler method is processed, but how can I redirect to some error page in exception handler method?  I'm working on school project and according to everything what was presented in course (and what I was able to figure out from documentation) this should work.

        • 1. Re: Seam 3 exception handler - redirection doesn't work
          lightguard

          Pretty sure I've answered this post a time or two in other posts.

          • 2. Re: Seam 3 exception handler - redirection doesn't work
            lightguard

            They're teaching you Seam 3 in school? That's pretty cool.

             

            As far as I know this should work at that phase. Do you have any exceptions that happen? What can you see when you're debugging?

            • 3. Re: Seam 3 exception handler - redirection doesn't work
              pseudoem

              Oh, it seems like I had deleted my post right before you answered, I should have edited it instead. I've made redirection work (probabbly some silly mistake because I still don't know what was wrong) .

               

              But I would be glad if u can help me with one more thing. Is there a way to set http status code before redirect? Something other then this

               

                ExternalContext ex = facesContext.getExternalContext();
                      ex.setResponseStatus(403);
                      ex.setResponseHeader("location", "/403");
                      facesContext.responseComplete();
              

               

              Because if I'm correct, this can used with neither NavigationHandler#handleNavigation() nor with ExternalContext#redirect() - it would set status code back to 200.

               

               

              BTW: Yes, they're teaching us Seam 3 (also infinispan and other interesting things). It's a course taught by Red Hat staff.

              • 4. Re: Seam 3 exception handler - redirection doesn't work
                lightguard

                Jakub Cechacek wrote:

                 

                Oh, it seems like I had deleted my post right before you answered, I should have edited it instead. I've made redirection work (probabbly some silly mistake because I still don't know what was wrong) .

                 

                But I would be glad if u can help me with one more thing. Is there a way to set http status code before redirect? Something other then this

                 

                  ExternalContext ex = facesContext.getExternalContext();
                        ex.setResponseStatus(403);
                        ex.setResponseHeader("location", "/");
                        facesContext.responseComplete();
                

                 

                Because if I'm correct, this can used with neither NavigationHandler#handleNavigation() nor with ExternalContext#redirect() - it would set status code back to 200.

                 

                 

                BTW: Yes, they're teaching us Seam 3 (also infinispan and other interesting things). It's a course taught by Red Hat staff.

                 

                You'll need to call the requestComplete() method on FacesContext.

                 

                Jakub Cechacek wrote:

                 

                BTW: Yes, they're teaching us Seam 3 (also infinispan and other interesting things). It's a course taught by Red Hat staff.

                Looks like someone didn't get the message that

                • 5. Re: Seam 3 exception handler - redirection doesn't work
                  vaclav_dedik

                  There is no such method as requestComplete() defined on FacesContext. See doc http://docs.oracle.com/javaee/6/api/javax/faces/context/FacesContext.html

                  • 6. Re: Seam 3 exception handler - redirection doesn't work
                    lightguard

                    Sorry, was going off memory. it's responseComplete()