12 Replies Latest reply on Apr 30, 2007 6:36 AM by courtneycouch

    @Startup (possible to have this occur post session creation?

    courtneycouch

      I have a bean that I would like to be instantiated imediately AFTER the session is done being created. Is there some way to do this?

      I'm running some methods on the facesContext that require the session to be created.

      Currently I have to just instantiate the ejb in the template.xhtml file with some innocuous call to a method that doesnt do anything. Since that method wont be called until the session is created.

      The drawback is that I have some call in my view whose sole purpose is to check to ensure an object is instantiated. It also means i have to have a pointless call for every future request.

      I would really prefer some sort of @PostStartup or some other more fine grained access to when the object is instantiated. Not sure if its possible and undocumented or possible and I just dont know how.

        • 1. Re: @Startup (possible to have this occur post session creat
          christian.bauer

          Maybe you can use one of the built-in events you can find in section 5.1.3 of the documentation.

          • 2. Re: @Startup (possible to have this occur post session creat
            courtneycouch

            None quite fit the point I need the method called..

            In essense I would need something like:

            org.jboss.seam.postCreateContext. ? called after the context is created

            but there doesnt appear to be that kind of granularity.

            The @Startup annotation isnt a pre or post session creation.. it occurs during session creation.

            • 3. Re: @Startup (possible to have this occur post session creat
              christian.bauer

              @Startup is not related to the session context, so I don't understand what you want. However, we had some other requests for more fine-grained interception of the Seam startup procedure and there might be open JIRA issues you can attach your request to. Search first, if nothing is there, open a new one.

              • 4. Re: @Startup (possible to have this occur post session creat
                courtneycouch

                 

                "christian.bauer@jboss.com" wrote:
                @Startup is not related to the session context, so I don't understand what you want. However, we had some other requests for more fine-grained interception of the Seam startup procedure and there might be open JIRA issues you can attach your request to. Search first, if nothing is there, open a new one.


                As I understand it @Startup does have to do with the session context. According to the documentation (22.1) "@Startup Specifies that a session scope component is started immediately at session creation time."

                I guess I was hoping there was some way to control whether it "Specifies that a session scope component is started immediately before/at/after session creation time." rather than simply "at".

                I'll check for requests. Thanks.

                • 5. Re: @Startup (possible to have this occur post session creat
                  pmuir

                  Seam's session context is driven by the web application. Seam is notified when the session has been created and processes the creation of @Startup @Scope(SESSION) components. We are calling the hooks as late as possible afaics.

                  What are you trying to do - which methods? What is going wrong - whats the stack?

                  • 6. Re: @Startup (possible to have this occur post session creat
                    courtneycouch

                     

                    "petemuir" wrote:
                    Seam's session context is driven by the web application. Seam is notified when the session has been created and processes the creation of @Startup @Scope(SESSION) components. We are calling the hooks as late as possible afaics.

                    What are you trying to do - which methods? What is going wrong - whats the stack?


                    I'm trying to initialize some managed-beans configured in faces-config.

                    The reason for this is that ajax4jsf mediaOutput components cant be seam component. They need to be simply managed-beans. When I'm using managed-beans in a seam application the regular lifecycle stuff for managed-beans doesnt work since seam is in control.

                    What I was trying to do instead was simply (from inside a seam component)

                    fc.getApplication().getVariableResolver().resolveVariable("manageBean")

                    to get ahold of the managed bean, then inside the managed bean:

                    org.jboss.seam.contexts.Contexts.getSessionContext().get("someComponent")

                    So the managed-bean would simply be a facade into the real seam component that its calling. (as a workaround to ajax4jsf not letting me use seam components).

                    I need to have access to the seam contexts from the managed-bean and if I dont initialize the managed-bean from a seam component then org.jboss.seam.contexts.Contexts.getSessionContext().get() throws a null error.

                    Kind of a hack I suppose.. the problem is fc.getApplication().getVariableResolver().resolveVariable() called from within a @Create method of a component tahts marked @Startup just starts an infinite loop.

                    When I simply instantiate the seam component manually everything works perfectly.. the ajax4jsf stuff.. the managed-bean, etc.

                    Maybe I'm going about this the wrong way?

                    • 7. Re: @Startup (possible to have this occur post session creat
                      pmuir

                       

                      "courtneycouch" wrote:
                      The reason for this is that ajax4jsf mediaOutput components cant be seam component. They need to be simply managed-beans. When I'm using managed-beans in a seam application the regular lifecycle stuff for managed-beans doesnt work since seam is in control.


                      This is something that is broken then - we/a4j ought to fix this as you should be able to use a Seam component here. Have you talked to the a4j guys about this?

                      Kind of a hack I suppose.. the problem is fc.getApplication().getVariableResolver().resolveVariable() called from within a @Create method of a component tahts marked @Startup just starts an infinite loop.


                      Well yes, this is a loop ;) I haven't got the whole picture here, but, for your workaround, why not lazy-initialize the proxy?

                      • 8. Re: @Startup (possible to have this occur post session creat
                        courtneycouch

                         

                        "petemuir" wrote:
                        "courtneycouch" wrote:
                        The reason for this is that ajax4jsf mediaOutput components cant be seam component. They need to be simply managed-beans. When I'm using managed-beans in a seam application the regular lifecycle stuff for managed-beans doesnt work since seam is in control.


                        This is something that is broken then - we/a4j ought to fix this as you should be able to use a Seam component here. Have you talked to the a4j guys about this?

                        Kind of a hack I suppose.. the problem is fc.getApplication().getVariableResolver().resolveVariable() called from within a @Create method of a component tahts marked @Startup just starts an infinite loop.


                        Well yes, this is a loop ;) I haven't got the whole picture here, but, for your workaround, why not lazy-initialize the proxy?


                        Here is the thread from the ajax4jsf users: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=107203

                        Perhaps I misunderstood but I got the impression that ajax4jsf purposely doesnt operate in the way I'm trying "You can use the whole JSF lifecycle with restoring the session for each request to resources like this OR serialize only the required data and pass it directly to the method. " seems to imply that.

                        As far as lazy initializing, I need the managed-bean to have access to seam components, if its lazy initialized then its initialized outside of the seam context and cant access them. Seam has to initialize the managed beans so I have to create a seam component whose sole purpose is initializing the managed-beans. Since thats its only purpose, I simply have a #{managedBeanLoader.load} in the template.

                        Once the managed bean has a reference to a seam context its good to go..I was just hoping I could find a better way than call the seam component above on every seam request jsut to make sure that the managed-beans are instantiated from seam not ajax4jsf.



                        • 9. Re: @Startup (possible to have this occur post session creat
                          courtneycouch

                          Oops i missed part of that quote from the thread.

                          From the ajax4jsf thread:

                          "SergeySmirnov" wrote:
                          There is a dilemma there. You can use the whole JSF lifecycle with restoring the session for each request to resources like this OR serialize only the required data and pass it directly to the method.
                          Ajax4jsf uses the second approach. value attribute is used to point to the serializable data. The first approach has to high price (from the performance point of view, first of all).


                          • 10. Re: @Startup (possible to have this occur post session creat
                            pmuir

                             

                            "courtneycouch" wrote:
                            As far as lazy initializing, I need the managed-bean to have access to seam components, if its lazy initialized then its initialized outside of the seam context and cant access them. Seam has to initialize the managed beans so I have to create a seam component whose sole purpose is initializing the managed-beans. Since thats its only purpose, I simply have a #{managedBeanLoader.load} in the template.


                            Use Lifecycle.beginRequest() and Lifecycle.endRequest() to access Seam contexts, then use Component.getInstance() to get at the Seam components.

                            • 11. Re: @Startup (possible to have this occur post session creat
                              pmuir

                              Reading through Sergey's answers it sounds like we need to work on getting a4j:mediaOutput and Seam to work properly together.

                              • 12. Re: @Startup (possible to have this occur post session creat
                                courtneycouch

                                 

                                "petemuir" wrote:
                                Reading through Sergey's answers it sounds like we need to work on getting a4j:mediaOutput and Seam to work properly together.


                                That would be fantastic. in the meantime the Lifecycle.beginRequest() and Lifecycle.endRequest() looks like exactly what I needed.

                                Thanks.