2 Replies Latest reply on Dec 29, 2010 3:24 PM by mechtatel

    Automatic login redirection to home

    mechtatel

      Hi,


      I'm using Seam 2.1.2 with JBoss AS 5.1, Richfaces 3.3.3.


      What I'm trying to achieve is automatic redirection to home page from the loggin page if the user is currently logged.


      For example, if the user is on a given page and type manually the url of the loggin page then automaticlly has to be redirected to the home page.


      I was trying to use dummy action method or dummy page action without success. They were newer called.


      This is an example of dummy action method



      This is another example of dummy action



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




      So what is the proper way recomended by Seam to achieve this functionality?
      Or maybe I'm making somthing wrong probably.




       

        • 1. Re: Automatic login redirection to home
          ryneezy.ryan.samiley.live.com

          Have you tried...




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




          • 2. Re: Automatic login redirection to home
            mechtatel

            Thank you for your reply Ryan,



            Yes I tried your suggestion. Using evaluate not work with manually typing url direction, because then is not executed. Works well when is used action raised from s:link for example.


            That's worked for me.


            login.page.xml


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




            authenticator


            public String  checkLoggedIn() {
             if(identity.isLoggedIn()) {
              return "home";
             } else {
              return null;
             }
            }




            Hope that this can be useful for somebody. If there is a better way, please let me know.