3 Replies Latest reply on Feb 1, 2010 11:12 AM by piotr.sobczyk

    How to change pages.xml to control page flow

    granite2009
      I am new to SEAM. I generated a SEAM project both using seam gen and Eclipse JBoss Tools respectively. The login screen works. However, I cannot re-direct the login page to any page. I always go back to home page. I am looked everywhere for samples pages.xml without luck. I know this must be something simple that I forget to do. Plesse help.

      <?xml version="1.0" encoding="UTF-8"?>
      <pages xmlns="http://jboss.com/products/seam/pages"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd"

             no-conversation-view-id="/home.xhtml"
             login-view-id="/login.xhtml">

          <page view-id="/login.xhtml">
              <navigation>
                  <rule if-outcome="login">
                      <redirect view-id="/login2.xhtml"/>
                  </rule>
              </navigation>
          </page>
      </pages>
        • 1. Re: How to change pages.xml to control page flow
          piotr.sobczyk

          It's simple indeed :). You have a fragment:


          <navigation>
              <rule if-outcome="login">
                   <redirect view-id="/login2.xhtml"/>
              </rule>
          </navigation>



          You have to take care that the button/link that invokes navigation is:



          • <h:button action=login/>

          • <h:button action=#{someBean.someAction}/> - where someAction return String value login

          • <s:button view=/login2.xhtml/> - then you don't need navigation at all

          • 2. Re: How to change pages.xml to control page flow
            granite2009
            Thanks for you reply. That's what I found from the documentation. It did not work for me. I wasted 2 weeks on this. That's what I come up.
            1. There is a page named login.page.xml in the view folder that control the page flow. This is not documented in Seam 2.2. When I changed from /home.xhtml to /login2.xhtml, it worked.

            <?xml version="1.0" encoding="UTF-8"?>
            <page xmlns="http://jboss.com/products/seam/pages"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">

               <navigation from-action="#{identity.login}">
                  <rule if="#{identity.loggedIn}">
                     <redirect view-id="/home.xhtml"/>
                  </rule>
               </navigation>

            </page>

            2. I can control page flow if my bean return a page id, ie /login2.xhtml. This is not good since the page flow is hard coded in the bean.

            I just which this login.page.xml is documented. When it is a good time to use individual page control of pages???
            • 3. Re: How to change pages.xml to control page flow
              piotr.sobczyk

              1.



              There is a page named login.page.xml in the view folder that control the page flow

              Are login.page.xml and login.xhtml files in the same directory? There is a possibility to use many *.page.xml files for individual pages instead of one pages.xml descriptor. But you need to be sure that:



              • both page and navigation descriptor for it are in the same directory

              • page and descriptor have the same name except of extension



              For example you can have a directory tree:



              • Pages

              • mypage.xhtml

              • mypage.page.xml



              But maybe you should start from pages.xml global descriptor if something goes wrong - it's simplier case.


              The xml code you pasted seems to be correct.


              2. Yeah, it's rather a bad practice.



              When it is a good time to use individual page control of pages???

              you mean using *.page.xml instead of pages.xml? It really depends of your own preferences. But in my opinion you should choose one and keep it strictly, don't use both in the same application. *.page.xml allows you quickly find descriptor for some specific page you just type page name in "open resource" view in your IDE and you quickly found page descriptor instead of searching through one big pages.xml file.