8 Replies Latest reply on Aug 28, 2007 11:38 AM by Mohammad Norouzi

    @Startup and user session

    Mohammad Norouzi Novice

      Hi

      I have a Stateful session scoped component namely "userSettings". I want when user logged in its build method (annotated with @Create) being invoked.

      first I marked it with @Startup but when the pages are loading this component will load as well but at that time, there is no user logged in, so this throws an exception and after the user enters his username and password this component won't initialize for his session

      how can I make a component to be loaded just when a user is signing in? @Startup will load for any session even if no user signed in.

        • 1. Re: @Startup and user session
          Damian Harvey Master

          Outject it into the session scope when you perform the login.

          @Out(scope=ScopeType.SESSION) UserSettings userSettings;
          


          Cheers,

          Damian.


          • 2. Re: @Startup and user session
            Mohammad Norouzi Novice

             

            "damianharvey" wrote:
            Outject it into the session scope when you perform the login.


            but outject it from where? there is another component that performs authentication named "Authenticator" when login performed and the user logged in, at the same time, the userSettings doesn't exist to be outjected.

            my problem is that I want this component being loaded just right after logging in.

            • 3. Re: @Startup and user session
              Matt Drees Master

              Probably what I would do is put an @Observer("org.jboss.seam.postAuthenticate") method in your userSettings component.

              • 4. Re: @Startup and user session
                Mohammad Norouzi Novice

                 

                "matt.drees" wrote:
                Probably what I would do is put an @Observer("org.jboss.seam.postAuthenticate") method in your userSettings component.


                thanks matt.drees, it worked fine, but another problem came about, there are three other component which depend on this unique component method. In other words, after invoking this method some variable will be outjected so other comp. will inject those variables.

                how to manage this?

                • 5. Re: @Startup and user session
                  Matt Drees Master

                  I'm not sure what you mean.

                  • 6. Re: @Startup and user session
                    Mohammad Norouzi Novice

                     

                    "matt.drees" wrote:
                    I'm not sure what you mean.


                    well, let me explain more. when a user logged in, the application should find which fields and categories he is allowed to search so I defined an action in which a Map of accessible fields will be created. this map is creating after authenticating the user (using the solution you suggest: @Observer)

                    now other actions like Exporting, query builder , etc need to work only with authorized fields and these are presented by the same map. I need to notify them as well to initialize themself. I can use Events.instance().raiseEvent to notify the other actions but I think this is not good. what do you think?



                    • 7. Re: @Startup and user session
                      Matt Drees Master

                      Why do you think raiseEvent is bad? That's probably what I would use. If the second set of initializers depend on contextual variables outjected from the first initializer, I would probably use @RaiseEvent instead of Events.instance.raiseEvent, because the second approach won't do outjection before raising the event, and the first approach will. (I think; haven't tested, but from looking at seam src, it should)

                      • 8. Re: @Startup and user session
                        Mohammad Norouzi Novice

                        well, I didn't know about @RaiseEvent, I will try it

                        the thing that make me reluctant to use Event...raseEvent is that, in my opinion, if you use this too much it will make your application complex and hard to understand and debug it in future

                        anyway, thank you very much for your help, currently I am using the same Events...raseEvent() but I will take a look at @RaiseEvent