7 Replies Latest reply on Sep 11, 2008 9:33 PM by Andrew Elegante

    Seam navigation ignored?

    Andrew Elegante Newbie

      Hi,


      What I'm trying to do is redirect users to a password change page if they have been flagged in the database (temporary password, password expired, etc...).  I've been trying to accomplish this via navigation rules in pages.xml and it seems like the navigation rules are simply ignored.


      Because of the issue with RichFaces and login required I've put all of my 'secured' pages under the secure folder.  Here is what I started with:


      <page view-id="/secure/*" login-required="true">
          <navigation>
              <rule if="#{loggedInEmployee.forcePasswordChange}">
                    <redirect view-id="/secure/employee/changePassword.xhtml" />
               </rule>
          </navigation>
      </page>
      



      When I login, I'm sent to the /secure/home.seam page but I would have expected it to send me to the changePassword page.  I'm basing this assumption on the following from the booking demo:


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



      Based on this code I would assume that if you tried to hit /home.xhtml you would just be redirected to /main.xhtml.  However, even on the seam demo site http://seam.demo.jboss.com/home.seam this does not work and seems to be the source of this issue.


      I even tried modifying my login.page.xml with its own navigation rule:


              <navigation>
                    <rule if="#{loggedInEmployee.forcePasswordChange}">
                        <redirect view-id="/secure/employee/changePassword.xhtml" />
                   </rule>
              </navigation>
      



      This did not work either.  In fact, as I tested it, the only time I could get rules to fire was when I specified an action in a link i.e.


      <s:link action="home" value="#{messages['home']}"/>
      



      As opposed to


      <s:link view="/secure/home.seam" value="#{messages['home']}"/>
      



      If I click the link that has the action in it, I am redirected to the changePassword page but if I click the link with a view Id in it I'm not redirected.  Also if I'm on the changePassword page and I manually enter a different URL in the browser no redirect occurs.


      Can someone point out to me what I'm doing wrong?  If there's a better way to do the redirect I'm all ears but it has to redirect from any other page after they've logged in.


      Thanks,


      Drew

        • 1. Re: Seam navigation ignored?
          Guillaume Jeudy Master

          What are your navigation rules for the login page? I think if more than 1 rule matches then the most specific takes precedence.

          • 2. Re: Seam navigation ignored?
            Andrew Elegante Newbie

            In my original post I included my login.pages.xml but I've also tried adding this to the pages.xml to no avail:


                <page view-id="/login.xhtml" login-required="false">
                     <navigation>
                          <rule if="#{identity.loggedIn}">
                               <redirect view-id="/secure/home.xhtml" />
                          </rule>
                          <rule if="#{loggedInEmployee.forcePasswordChange}">
                               <redirect view-id="/secure/employee/changePassword.xhtml" />
                          </rule>
                     </navigation>
                </page>
            



            Neither of these rules are triggered as I can manually hit the login.seam page and I'm not redirected to either /secure/home or /secure/employee/changePassword

            • 3. Re: Seam navigation ignored?
              Guillaume Jeudy Master

              Have you tried adding

              <navigation from-action="#{myloginaction}"

              in your login.xhtml page element ?

              • 4. Re: Seam navigation ignored?
                Andrew Elegante Newbie

                Yes, I tried this by modifying the login.page.xml that seam-gen produces to look like this:


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



                The loggedIn rule was already there so I just added my additional rule.


                Thanks for your responses but I want to be clear that this has to work if they hit ANY page, not just when they have logged in.  As it stands I can force the redirect in my authenticator action but the user could simply navigate to another page via the browser and skip having to change their password.

                • 5. Re: Seam navigation ignored?
                  Guillaume Jeudy Master

                  I never solved a problem like this but have you checked:


                  Page actions


                  if you put an action on the page element you can have it execute in a chain manner even if you have more than 1 matching rule:


                   <page view-id="/secure/*" login-required="true" action="#{loggedInEmployee.forcePasswordChange}">
                      <navigation from-action="#{loggedInEmployee.forcePasswordChange}">
                          <rule if-outcome="changepass">
                                <redirect view-id="/secure/employee/changePassword.xhtml" />
                           </rule>
                      </navigation>
                  </page>
                  



                  Try the above, if it doesn't work maybe a variant works.

                  • 6. Re: Seam navigation ignored?
                    Andrew Elegante Newbie

                    Alright, that finally did the trick!  I got it to work this way:


                        <page view-id="*" login-required="false" >
                             <action execute="changePassword" if="#{loggedInEmployee.forcePasswordChange}"/>
                             <navigation >
                                  <rule if-outcome="changePassword">
                                       <render view-id="/secure/employee/changePassword.xhtml" ></render>
                                  </rule>
                             </navigation>
                        </page>
                    



                    I'm still curious, however, as to why the methodology shown in the demo and the seam-generated project don't work when you manually navigate to a page.  Are the filters not applied or what?

                    • 7. Re: Seam navigation ignored?
                      Andrew Elegante Newbie

                      Hmm, the page action methodology is not very sound because whenever an ajax request is submitted it evaluates the action and the page is re-rendered if it fires (hence I can't have any ajax going on in the change password screen).  I still feel like the original way should work and would appreciate hearing from someone on the Seam team as to why it doesn't work.


                      Drew