2 Replies Latest reply on Apr 30, 2008 12:36 PM by haefti

    Problem with redirecting in pages.xml

    haefti

      Hi!


      I have a problem with redirecting using pages.xml.


      I have a classic CRUD application with a list view where you can pick an item to edit (in a second view) and another button to create a new one.
      The edit view shows the details of a chosen item and you have a button to save the updates or to cancel. Both buttons are supposed to lead back to the list view.


      The relevant part of my pages.xml looks like this:


           <page view-id="/authorList.xhtml">
                <navigation>
                     <rule if-outcome="create">
                          <redirect view-id="/authorEdit.xhtml"/>
                     </rule>
                </navigation>
           </page>
      
           <page view-id="/authorList.xhtml">
                <navigation>
                     <rule if-outcome="edit">
                          <redirect view-id="/authorEdit.xhtml"/>
                     </rule>
                </navigation>
           </page>
      
      
           <page view-id="/authorEdit.xhtml">
                <navigation>
                     <rule if-outcome="save">
                          <redirect view-id="/authorList.xhtml"/>
                     </rule>
                </navigation>
           </page>
      
           <page view-id="/authorEdit.xhtml">
                <navigation>
                     <rule if-outcome="cancel">
                          <redirect view-id="/authorList.xhtml"/>
                     </rule>
                </navigation>
           </page>



      As you can see if a method returns create or edit in the list view the client should be redirected to the edit view.


      If a method returns save or cancel in the edit view the client should be redirected to the list view.



      Due to handling pretty similar data (assets) I have a abstract super class for my session beans (AssetManager) which contains the action methods for creating, editing, etc. The actual assets (Author, Picture, etc.) are managed by session beans called AuthorManager, PictureManager, etc. which inherit from AssetManager.


      Here are the relevant methods of the super class:



      @Begin(join = true)
      public String createAsset() {
      
           // some working code to create a new object
           
           return "create";
      }
           
      @Begin(join = true)
      public String editAsset() {
           String returnValue;
           if (selectedAsset != null) {
                returnValue = "edit";
           } else {
                returnValue = null;
           }
           return returnValue;
      }
           
      @Begin(join = true)
      public String findAsset() {
           String returnValue;
           if (assetId != null) {
      
                // some working code to get an asset from the database
      
                returnValue = "edit";
           } else {
                returnValue = null;
           }
           return returnValue;
      }
      
      @End
      public String saveAsset() {
      
           // some working code to save an asset to the database
           
           return "save";
      }
      
      @End
      public String cancel() {
           return "cancel";
      }
      



      My problem is that it does not work with create and with save (even though the entries in the pages.xml seem to me to be absolutely the same like the working ones). The methods returning these strings are invoked (I can see this in the log) but the same view is rendered even though no exception is thrown.


      The whole application does work if I return directly the name of the desired views as strings (so it is not a bug in the business logic) but I would like to handle all my navigation in the pages.xml so hopefully there is a soution for my problem.


      BTW, is there any overview over the allowed tags and attributes in the pages.xml? (The manual has only examples and gathering the information from the schema file is a bit annoying.)


      Thanks!

        • 1. Re: Problem with redirecting in pages.xml
          andygibson.contact.andygibson.net

          Hey Michael,


          You probably need to group the two different rules for each page under the same page tag. Otherwise your second definition will overwrite the first.
          Merge the two rules for each page under one single page section as shown below. This also explains how returning the view from the method works, since it doesn't rely on the navigation rules.


          <page view-id="/authorList.xhtml">
               <navigation>
                    <rule if-outcome="create">
                         <redirect view-id="/authorEdit.xhtml"/>
                    </rule>
                    <rule if-outcome="edit">
                         <redirect view-id="/authorEdit.xhtml"/>
                    </rule>
               </navigation>
          </page>
          
          
          <page view-id="/authorEdit.xhtml">
               <navigation>
                    <rule if-outcome="save">
                         <redirect view-id="/authorList.xhtml"/>
                    </rule>
          
                    <rule if-outcome="cancel">
                         <redirect view-id="/authorList.xhtml"/>
                    </rule>
               </navigation>
          </page>
          
          



          Cheers,


          Andy Gibson

          • 2. Re: Problem with redirecting in pages.xml
            haefti

            Thanks a lot!


            This is the solution. That is one reason why I look for a complete overview of allowed tags and attributes for the pages.xml.