10 Replies Latest reply on Feb 19, 2007 2:06 PM by fernando_jmt

    Problems with navigations with null outcomes

    fernando_jmt

      Hi.

      I am just changing all navigation rules from faces-config.xml to pages.xml.

      Then when my action returns a null outcome it does not redisplay the current page.

      I have this method in my component:

      @Stateful
      @Name("userManager")
      public class UserManagerAction {
      ...
      public String create() {
       em.persist(user);
       em.flush();
       return "userList";
       } catch (EntityExistsException e) {
       return Outcome.REDISPLAY;
       }
      }
      }
      


      And according the documentation (1.1.6) I tried two configuration in my pages.xml:

      a) (This is not in the docs, but I saw it in this forum)

      
      <page view-id="/user/new.xhtml" no-conversation-view-id="/user/list.xhtml">
       <navigation from-action="#{userManager.create}">
       <redirect view-id="/user/list.xhtml"/>
       </navigation>
       </page>
      
      



      b) (according the book)

      <page view-id="/user/new.xhtml" no-conversation-view-id="/user/list.xhtml">
       <navigation from-action="#{userManager.create}">
       <rule>
       <redirect view-id="/user/list.xhtml"/>
       </rule>
       </navigation>
       </page>
      



      In the both cases (a, b) after userManager.create() returns null or Outcome.REDISPLAY the current page is not redisplayed, I always get the list.xhtml page.


      Anyone knows why?

      Could this be a bug? or is it my fault?

      Please help me.

      BTW, it could be good idea to add to Outcome class something like:
      Outcome.SUCCESS. This because in these cases (using navigations with String returning methods and pages.xml navigations) the outcome sometimes does not matter. I know we can use void methods, but adding error messages and checking those in the navigation rule involves more configuration steps, I think unnecessary for these cases. What do you think?



      Thanks in advance.




        • 1. Re: Problems with navigations with null outcomes
          pmuir

          Try

          <page view-id="/user/new.xhtml" no-conversation-view-id="/user/list.xhtml">
           <navigation from-action="#{userManager.create}">
           <rule if-outcome="userList">
           <redirect view-id="/user/list.xhtml"/>
           </rule>
           </navigation>
           </page>
          


          • 2. Re: Problems with navigations with null outcomes
            fernando_jmt

            Yes, adding from-outcome works. I also did that before posting here.
            So, this means we need to add a rule even for null outcomes?

            I had seen in the seam reference (1.1.6GA), page 87, this:

            "Null outcomes are a special case in JSF. The null outcome is interpreted to mean "redisplay the page". The following
            navigation rule matches any non-null outcome, but not the null outcome:"

            <page view-id="/editDocument.xhtml">
             <navigation from-action="#{documentEditor.update}">
             <rule>
             <render view-id="/viewDocument.xhtml"/>
             <rule/>
             </navigation-case>
            </navigation-rule>
            



            So, should the reference be updated?

            Or?




            • 3. Re: Problems with navigations with null outcomes
              gavin.king

              The docs are correct, are you sure you are really observing this?

              • 4. Re: Problems with navigations with null outcomes
                gavin.king

                I just retested this. A never matches a null outcome.

                • 5. Re: Problems with navigations with null outcomes
                  fernando_jmt

                   

                  "gavin.king@jboss.com" wrote:
                  The docs are correct, are you sure you are really observing this?



                  Yes, I am sure.

                  I have this in pages.xml
                  <page view-id="/user/new.xhtml" no-conversation-view-id="/user/list.xhtml">
                   <navigation from-action="#{userManager.create}">
                   <rule>
                   <redirect view-id="/user/list.xhtml"/>
                   </rule>
                   </navigation>
                   </page>
                  


                  And this in my create method:

                  public String create() {
                  
                  
                   try {
                   em.persist(user);
                   em.flush();
                   facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_INFO,
                   "Common.message.created", user.getFullName());
                   return "userList";
                   } catch (EntityExistsException e) {
                  
                   facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_ERROR, "User.error.duplicate");
                   return Outcome.REDISPLAY;
                   }
                   }
                  
                  



                  And it doesn't work. I'm always getting the error messages (cause of EntityExistsException caught):
                  * The username is already registered.
                  * Transaction failed

                  in the list.xhml instead of the new.xhtml view.

                  I'm using
                  tomcat 5.5.17
                  java 1.5.x
                  Seam 1.1.6GA CVS build at 02/12/2007


                  Any ideas why am I getting this behaviour?


                  Thanks.



                  • 6. Re: Problems with navigations with null outcomes
                    gavin.king

                    Return "null", not "Outcome.REDISPLAY" if you are using current CVS. Outcome.REDISPLAY is only meant for use inside annotations, and the old OutcomeInterceptor was recently removed, to help reduce stacktraces and increade performance.

                    • 7. Re: Problems with navigations with null outcomes
                      fernando_jmt

                       

                      "gavin.king@jboss.com" wrote:
                      Return "null", not "Outcome.REDISPLAY" if you are using current CVS. Outcome.REDISPLAY is only meant for use inside annotations, and the old OutcomeInterceptor was recently removed, to help reduce stacktraces and increade performance.



                      I tried with both. And neither null or Outcome.REDISPLAY works.


                      "fernando_jmt" wrote:

                      In the both cases (a, b) after userManager.create() returns null or Outcome.REDISPLAY the current page is not redisplayed, I always get the list.xhtml page.


                      I'll try with a recent CVS copy again. If it will not work, I'll tell you.


                      • 8. Re: Problems with navigations with null outcomes
                        fernando_jmt

                         

                        "gavin.king@jboss.com" wrote:
                        Return "null", not "Outcome.REDISPLAY" if you are using current CVS. Outcome.REDISPLAY is only meant for use inside annotations, and the old OutcomeInterceptor was recently removed, to help reduce stacktraces and increade performance.



                        I tried with both. And neither null or Outcome.REDISPLAY works.


                        "fernando_jmt" wrote:

                        In the both cases (a, b) after userManager.create() returns null or Outcome.REDISPLAY the current page is not redisplayed, I always get the list.xhtml page.


                        I'll try with a recent CVS copy again. If it will not work, I'll tell you.


                        • 9. Re: Problems with navigations with null outcomes
                          gavin.king

                          I simply don't believe this (because I tested it), so you'll need to debug into the Seam source code, by putting a breakpoint in Pages.navigate(), and find the reason.

                          • 10. Re: Problems with navigations with null outcomes
                            fernando_jmt

                            Gavin,

                            After I spent a lot of time trying to make this works (changing examples, from 1.1.6, CVS, debugging Seam code and so on), I found the reason:

                            The problem was that I was using the el-ri.jar which comes with ICEFaces 1.5.3 distribution.

                            I change back to el-ri.jar from Seam distribution and all works fine.

                            I don't know why this happen, it seems they are different implementations, even the size is different (IceFaces 97Kb, Seam 95Kb form el-ri.jar).

                            Do you know something related this?

                            Anyway, Thanks you for your help.