6 Replies Latest reply on Feb 20, 2010 5:51 AM by Sergio Samayoa

    Force "company" selection after login

    Sergio Samayoa Newbie
      This is my problem:

      After a user has logged-in he/she must select a company before doing anything else. I tried redirecting to the company selection view in pages.xml and [view].page.xml but initial GET doesnt fire navigation rule.

      Reading thru seam reference it seems that what I need is an interceptor but before wasting time please tell me if I'm going in the correct direction. I'm not using EJB.

      Thanks.
        • 1. Re: Force "company" selection after login
          Denis Forveille Novice

          We had recently the same need.


          I suppose here that you use seam security with an authenticator component/method


          For this we use two things



          • a navigation rule in page.xml that redirect the user until a condition is met (he selected a company in your case)

          • in the Authenticator.authenticate() method, call Render.instance().setViewId(\<your view id name to select the company here\>)




          After the user has been authenticated, it will be redirect to the page you want, and with the navigation/rule statement in page.xml, it will stay on this page untill the condition set in pages.xml is false


          Hope this helps




          • 2. Re: Force "company" selection after login
            Sergio Samayoa Newbie
            Thanks for your response.

            I'm using the JpaIdentityStore, I'm not Authenticator.authenticate() but I guess is matter of some minor changes to use it with the JpaIdentityStore.

            About navogation rule, I tried this:

                 <page view-id="*">
                      <navigation>
                           <rule if-outcome="home">
                                <redirect view-id="/home.xhtml" />
                           </rule>
                           <rule if="#{identity.isLoggedIn and empreaActual eq null}">
                                <redirect view-id="/selemp.xhtml" />
                           </rule>
                      </navigation>
                 </page>

            But the app never goes to the view.

            Some little more help please.

            Regards.
            • 3. Re: Force "company" selection after login
              Denis Forveille Novice

              Maybe extends JpaIdentityStore, override  the authenticate method, call super.authenticate() in there and if the result is true then call Render.instance().setViewId(/selemp.xhtml).


              Should work.


              • 5. Re: Force "company" selection after login
                Stuart Douglas Master

                <page view-id="*" action="#{''.toString()}">
                  <navigation from-action="#{''.toString()}" >
                     <rule if="#{identity.isLoggedIn and empreaActual eq null}">
                       <redirect view-id="/selemp.xhtml" />
                     </rule>
                  </navigation>
                </page>
                
                



                Note the use of a dummy action, navigation rules are only evaluated after an action is run.

                • 6. Re: Force "company" selection after login
                  Sergio Samayoa Newbie
                  Thanks Stuart.
                  I will have on mind - I never figure out that way!

                  By the way, I solve my problem using events:

                  components.xml:
                       <event type="com.ls.noHayEmpresaActual">
                            <action execute="#{redirect.captureCurrentView}" />
                            <action execute="#{manager.redirect('/selemp.xhtml')}" />
                       </event>
                       <event type="com.ls.yaHayEmpresaActual">
                            <action execute="#{redirect.returnToCapturedView}" />
                       </event>

                  And each view which needs a selected company runs an component's action like (actual code):

                  Some.page.xml:
                       <action execute="#{eventosEmpresa.hayEmpresaActual}" />

                  And the "eventosEmpresa" component raises both events (partial EventosEmpresa class):

                       @In(required = false)
                       @Out(required = false)
                       protected Empresa empresaActual;

                       @In(required = false)
                       protected Events events;

                       @Logger
                       private Log log;

                       public void hayEmpresaActual() {
                            if (empresaActual == null && events != null) {
                                 log.info("hayEmpresaActiva(): no hay empresa activa.");
                                 events.raiseEvent(EventosEmpresa.NO_HAY_EMPRESA_ACTUAL);
                            }
                       }

                       public void setEmpresaActual(Empresa empresaActual) {
                            this.empresaActual = empresaActual;
                       }

                       public void seleccionarEmpresa() {
                            if (empresaActual != null && events != null) {
                                 log.info("seleccionarEmpresa(): Ya hay empresa activa.");
                                 events.raiseEvent(EventosEmpresa.YA_HAY_EMPRESA_ACTUAL);
                            }
                       }

                  "seleccionarEmpresa()" is called from company selection view's command link.

                  So far, works great even with pages which requires login.

                  I posted my solution because maybe someone nees the same functionality.

                  Seam rules!

                  Regards.