4 Replies Latest reply on Aug 14, 2009 12:31 AM by asookazian

    Call method on http session creation

    frer

      Hi,


      I'm trying to set a certain number of parameters as soon as the user accesses the web site.  I used to do these operations when the user logged in to the website but for a public site, this will not necessarily be the case.


      How can I call a method as soon as the http session for the user is created.  Is there a component for that?  Or an event?


      Any help would be greatly appreciated.


      François

        • 1. Re: Call method on http session creation
          asookazian

          You can try something like this:


          @Name("foo")
          @Scope(ScopeType.SESSION) 
          @Startup
          public class Foo {
          
             @Logger 
             private Log log;
          
             @Out(required=false) 
             private String s1;
          
             @Create
             public void bar(){
                  log.info("in bar()");
                  //set your variables and outject
                  s1 = "baz";
             }
          
          }



          output:


          12:53:24,731 INFO  [EARDeployer] Started J2EE application: file:/C:/java/jboss-4.2.3.GA/server/default/deploy/jboss-seam-booking.ear/
          12:53:30,715 INFO  [TestOnStartupSession] in bar()



          There is also this event:


          org.jboss.seam.security.loginSuccessful which is raised when a new session is created and authentication occurs


          that you can observe using @Observer in a session-scoped Seam component.

          • 2. Re: Call method on http session creation
            frer

            THank you for your reply Arbi.


            I'll give it a try but I don't think its what I'm looking for.  I want the method to be called when a user accesses the site (so his HTTP session is created).  The user will NOT have logged in yet but I still want a method to be called so I can check some of his settings and customize the application (without his user info but with the http meta info)).


            Do you know how this would be possible?


            • 3. Re: Call method on http session creation
              frer

              Ah you were right!  Sorry about that I thought the @Startup would be called only on application startup....


              It worked great!


              Thanks for your help

              • 4. Re: Call method on http session creation
                asookazian

                If you use @Application and @Startup at the class level and @Create at the method level, that method will execute when the app is deployed (i.e. prior to session creation).