4 Replies Latest reply on Mar 11, 2010 8:25 AM by Jarkko Miettinen

    Forwarding from non-existing pages

    Jarkko Miettinen Newbie

      My problem is simple: I would like to have all requests to non-existing pages (e.g. /foo or /foo.seam) redirected to starting page with a simple message.
      My approach was to create notFound.seam and accompanying redirector bean as it seemed that I could not do everything I wanted in pages.xml with execute and redirect implicit object.


      So now I have in web.xml:
       


        <error-page>
              <error-code>404</error-code>
              <location>/notFound.seam</location>
          </error-page>




      in pages.xml:


         <page view-id="/notFound.xhtml" login-required="true">
              <action execute="#{redirector.notFoundRedirect}"/>
          </page>




      And in Redirector.java:



      @Stateless
      @Name("redirector")
      public class Redirector implements RedirectorAction {
         @Override
          public String notFoundRedirect() {
              final Redirect redir = Redirect.instance();
              redir.setParameter("message", "page_not_available");
              redir.setViewId("/home.seam");
              redir.execute();
              return "success";
          }
      }




      Redirects from non-existing pages that do not end in *.seam are forwarded ok but when I request doesnotexist.seam, the forwarding is first
      done at least partially (the bean method is called).


      Then in restore view-phase, invoked through ApplicationDispatcher#doForward, SeamPhaseListener#commitOrRollback throws IllegalStateException that is caused
      by javax.ejb.NoSuchEJBException: Could not find stateful bean: a124i-h6fdb0-g6lsexs5-1-g6lu8csz-aj.


      To me it seems that org.jboss.ejb3.cache.simple.SimpleStatefulCache#get that throws this exception tries to find a bean for the given address but does not find it.


      What would be the correct way to do such redirects? In what way am I misusing Seam in my solution?



        • 1. Re: Forwarding from non-existing pages
          Konstantin Larionov Newbie

          I was going to implement the same behavior in my application, but was stopped by the same problem.
          I posted the question in this thread.


          Unfortunately, no reply was received.


          After that, I created Jira Issue because I think it is Seam bug. At first this issue was rejected with suggestion to use Seam forum to find the solution. I re-opened it providing the link to this forum and after that it was simply deleted without any explanation.

          • 2. Re: Forwarding from non-existing pages
            Jarkko Miettinen Newbie

            It seems that we have the same problem.


            I will wait a bit, hoping for another reply, then try again to the bottom of this and possibly open a Jira issue.


            The whole thing baffles me as I am trying to do quite a simple thing that seems to be impossible. I am probably just doing something in a non-Seamy way yet scanning through Seam community documentation for redirect left me as puzzled as ever.

            • 3. Re: Forwarding from non-existing pages
              Shervin Asgari Master

              Why did you create this component as a Stateless EJB? Try either a Stateful or a normal java bean. That might work better when I see your exception.


              Also a @AutoCreate would help on your @Stateless

              • 4. Re: Forwarding from non-existing pages
                Jarkko Miettinen Newbie

                I actually dropped my notfound page and the accompanying bean and now I only have the following thing is web.xml:


                    <error-page>
                        <error-code>404</error-code>
                        <location>/home.seam?message=page_not_available</location>
                    </error-page>




                This works ok when requesting non-existent resources that do not end in .seam but then requesting doesnotexist.seam, I get the same stack trace as Konstantin, i.e.
                java.lang.IllegalStateException with message: Could not commit transaction
                Caused by javax.ejb.NoSuchEJBException with message: Could not find stateful bean: a124i-ku0fc0-g6n821lj-1-g6n8bmrx-9x
                The full stack trace is available at Pastebin.


                So my question remains: Is forwarding requests to non-existing Seamy resources illegal or am I just doing it wrong?