11 Replies Latest reply on Jul 11, 2007 10:40 AM by Ning Zhao

    [2.0beta1]s:button + pages.xml behaviour change

    Ning Zhao Apprentice

      I had this code always worked prior to the migration to 2.0 beta1:

      in the new-recipe.xhtml:

      <s:button value="Cancel Creating New Recipe"
       action="#{recipeManager.cancelNewRecipe}" view="/home.xhtml" />
      

      in the pages.xml:
      <page view-id="/new-recipe.xhtml">
       <navigation from-action="#{recipeManager.cancelNewRecipe}">
       <redirect view-id="/home.xhtml" />
       </navigation>
      </page>
      


      in the RecipeManagerImpl.java:
      @End
      public void cancelNewRecipe() {
       entityManager.remove(this.recipe);
      }


      But now the page simply did not redict, I had to change the code in new-recipe.xhtml to make the redirection happen:
      <s:button value="Cancel Creating New Recipe"
       action="#{recipeManager.cancelNewRecipe}" view="/home.xhtml" />
      


      Anybody knows why? Thanks in advance!

        • 1. Re: [2.0beta1]s:button + pages.xml behaviour change
          Gavin King Master

          It should work. Put a breakpoint in Pages.callAction() and find out why the navigation rule doesn't get triggered.

          Let me know how you go.

          • 2. Re: [2.0beta1]s:button + pages.xml behaviour change
            Ning Zhao Apprentice

            Ah sorry, there is copy&paste mistake in my last post. It should be:


            I had this code always worked prior to the migration to 2.0 beta1:

            in the new-recipe.xhtml:

            <s:button value="Cancel Creating New Recipe"
             action="#{recipeManager.cancelNewRecipe}" />
            
            

            ... (the rest is the same)


            Sorry for the confusion. And I'll post investigation of this behaviour in minutes....

            • 3. Re: [2.0beta1]s:button + pages.xml behaviour change
              Ning Zhao Apprentice

              Here is the first experiment I did today.

              in the new-recipe.xhtml:

              ...
              <s:link value="Add an ingredient" action="#{ingredientManager.startAddAnIngredient(recipeManager.recipe)}" />
              ...
              <s:button value="Cancel Creating New Recipe" action="#{recipeManager.cancelNewRecipe}" />
              ...
              


              in the pages.xhtml, at first it was like below. It prevented the "Cancel Creating New Recipe" button redirecting to /home.xhtml:

              <page view-id="/new-recipe.xhtml">
               <navigation from-action="#{ingredientManager.startAddAnIngredient(recipeManager.recipe)}">
               <redirect view-id="/new-recipe.xhtml" />
               </navigation>
              </page>
              
              <page view-id="/new-recipe.xhtml">
              
               <navigation from-action="#{recipeManager.cancelNewRecipe}">
              
               <redirect view-id="/home.xhtml" />
              
               </navigation>
              
              </page>
              
              
              
              
              


              When I modified the code in page.xhtml like below (disabled the first block), the "Cancel..." button worked! And, the "Add an ingredient" link worked correctly too, even if I commented the first block out.
              <!--
              <page view-id="/new-recipe.xhtml">
               <navigation from-action="#{ingredientManager.startAddAnIngredient(recipeManager.recipe)}">
               <redirect view-id="/new-recipe.xhtml" />
               </navigation>
              </page>
              -->
              
              <page view-id="/new-recipe.xhtml">
               <navigation from-action="#{recipeManager.cancelNewRecipe}">
               <redirect view-id="/home.xhtml" />
               </navigation>
              </page>
              


              • 4. Re: [2.0beta1]s:button + pages.xml behaviour change
                Ning Zhao Apprentice

                Then I thought maybe both actions from the same page confused the processor of the pages.xml. But I also have code like this in the pages.xml, both buttons on the /register.xhtml worked very well!

                <page view-id="/register.xhtml">
                 <navigation from-action="#{userManager.register}">
                
                 <redirect view-id="/home.xhtml" />
                
                 </navigation>
                
                </page>
                
                
                
                <page view-id="/register.xhtml">
                
                 <navigation from-action="#{userManager.cancel}">
                
                 <redirect view-id="/home.xhtml" />
                
                 </navigation>
                
                </page>
                


                both "register" and "cancel" buttons on the register.xhtml did redirect to /home.xhtml.

                • 5. Re: [2.0beta1]s:button + pages.xml behaviour change
                  Ning Zhao Apprentice

                  Here is the third experiment.

                  In home.xhtml:

                  <rich:panel>
                   <p>You can:</p>
                   <ul>
                   <li><s:link action="#{userManager.startRegistration}" value="Register as a new user" /></li>
                   <li><s:link action="#{recipeManager.startNewRecipe}" value="Create Recipe"/></li>
                   </ul>
                  </rich:panel>
                  


                  In the pages.xml:
                  <page view-id="/home.xhtml">
                   <navigation from-action="#{userManager.startRegistration}">
                   <redirect view-id="/register.xhtml" />
                   </navigation>
                  </page>
                  
                  <page view-id="/home.xhtml">
                   <navigation from-action="#{recipeManager.startNewRecipe}">
                   <rule if="#{recipeManager.recipe != null}">
                   <redirect view-id="/new-recipe.xhtml" />
                   </rule>
                   </navigation>
                  </page>
                  


                  The first link does _not_ redirect but the second link redirects! In order to make the first link actually takes me to the registration page, I would have to say:
                  <s:link action="#{userManager.startRegistration}" value="Register as a new user" view="/register.xhtml"/>
                  

                  in the home.xhtml.

                  Strange thing....

                  My development environment is: Seam 2.0 beta 1 the latest build from CVS, Java 1.6. Debian Lenny amd64 kennel or Windows XP 32bits.

                  Thanks in advance for any enlightenment!


                  Best Regards,
                  Ellen

                  • 6. Re: [2.0beta1]s:button + pages.xml behaviour change
                    Ning Zhao Apprentice

                    forgot to mention, all the action methods in the beans (userManager, recipeManager, ingredientManager.....) have the return type of void.

                    • 8. Re: [2.0beta1]s:button + pages.xml behaviour change
                      Ning Zhao Apprentice

                      Yes it is! By the way, I've doubled checked that all the actions expressed in the <s:link> or <s:button> were really executed and I did get the server side state as I wanted them to be. Only the page redirection did not happen anymore....

                      Thanks Pete!

                      Regards,
                      Ellen

                      • 9. Re: [2.0beta1]s:button + pages.xml behaviour change
                        Matt Drees Master

                        Is it legal to have multiple elements with the same view-id? I don't think it is... but I'd like to know if I'm wrong.

                        • 10. Re: [2.0beta1]s:button + pages.xml behaviour change
                          Ning Zhao Apprentice

                          Matt you are right. That was my mistake, sorry. I should have known more about the pages-2.0.xsd first.....Now I wrote the navigations this way:

                          <page view-id="/a.xhmtl">
                          ...
                          ...
                          ...


                          all the navigation rules work fine now. :-)

                          Regards,
                          Ellen

                          • 11. Re: [2.0beta1]s:button + pages.xml behaviour change
                            Ning Zhao Apprentice

                            sorry, I forgot to add the code tag...the code should be:

                            <page view-id="/a.xhtml">
                             <navigation>...</navigation>
                             <navigation>...</navigation>
                             ...
                            </page>