7 Replies Latest reply on Apr 27, 2006 2:06 PM by ryan dewell

    Custom PhaseListener timing

    ryan dewell Novice

      Upgrading from beta 1 to CR1. We use a custom PhaseListener executing afterPhase RESTORE_VIEW.

      Unfortunately we're having several problems migrating this to CR1 (was working in beta 1). This PhaseListener itself accesses Seam components so the timing of it is obviously crucial to the timing of the Seam context lifecycles.

      The error received is:

      20:28:37,253 ERROR [STDERR] Caused by: java.lang.IllegalStateException: No conversation context active
      20:28:37,254 ERROR [STDERR] at org.jboss.seam.ScopeType.getContext(ScopeType.java:88)
      20:28:37,254 ERROR [STDERR] at org.jboss.seam.Component.newInstance(Component.java:1160)
      20:28:37,282 ERROR [STDERR] at org.jboss.seam.Component.getInstance(Component.java:1107)
      20:28:37,282 ERROR [STDERR] at org.jboss.seam.Component.getInstance(Component.java:1090)
      20:28:37,283 ERROR [STDERR] at org.jboss.seam.Component.getInstanceToInject(Component.java:1214)
      20:28:37,283 ERROR [STDERR] at org.jboss.seam.Component.injectFields(Component.java:892)
      


      The only injected value for this particular component is an EntityManager. I understand that EntityManager's are conversation scoped, so that exception makes sense...

      What can we do here to make sure that we can get at a Seam managed entity manager when no conversation context is active? I'm not sure I understand the implications of what changed since beta 1.

      Any insight to this lifecycle might be helpful.

      Thanks,

      Ryan





        • 1. Re: Custom PhaseListener timing
          Gavin King Master

          Perhaps if you have your phase listener extend the Seam phase listener?

          • 2. Re: Custom PhaseListener timing
            ryan dewell Novice

            Between the phases listened to, and the ordering of the phase listeners in the faces-config, I should be able to have them fire in whatever order I need without extending Seam's phase listener.

            What is the earliest phase point (before/after) where I should be able to start accessing Seam managed components, especially a Seam managed extended persistence context?

            Ryan

            • 3. Re: Custom PhaseListener timing
              Gavin King Master

               

              "rdewell" wrote:
              Between the phases listened to, and the ordering of the phase listeners in the faces-config, I should be able to have them fire in whatever order I need without extending Seam's phase listener.


              Well, if you say so - then why do you need my help for?

              If you know how to go about freely ordering phaselisteners (according to the JSF spec), Just Do It.

              • 4. Re: Custom PhaseListener timing
                ryan dewell Novice

                I need to be able to use Seam components during createView of a ViewHandler (at least). This was working in beta 1, and we need to be to get back to that ability to upgrade.

                The problem with using Seam components then is that there is no conversation until you get to afterPhase RESTORE_VIEW leading to "conversation context not active" if you try to access them in createView.

                So I've hacked around this by trying to startup conversations in beforePhase RESTORE_VIEW:

                - Extending SeamExtendedManagedPersistencePhaseListener
                - Then:

                public void beforePhase(PhaseEvent arg0) {
                 super.beforePhase(arg0);
                 if (arg0.getPhaseId().equals(PhaseId.RESTORE_VIEW)){
                 ExternalContext ec = arg0.getFacesContext().getExternalContext();
                 Manager.instance().restoreConversation( ec.getRequestParameterMap() );
                 Lifecycle.resumeConversation(ec);
                 Manager.instance().handleConversationPropagation(ec.getRequestParameterMap() );
                 }
                }
                


                That gets things a little further along... however now I appear to be running into http://jira.jboss.com/jira/browse/EJBTHREE-540:

                11:02:43,668 ERROR [STDERR] org.hibernate.TransactionException: could not register synchronization with JTA TransactionManager
                 at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:174)
                 at org.hibernate.impl.SessionImpl.checkTransactionSynchStatus(SessionImpl.java:1824)
                


                So I have no idea (yet) if setting up the conversation in beforePhase RESTORE_VIEW is actually a workaround to using Seam components at that time.

                What I'm ultimately looking for is a valid way to start using Seam components, conversation scoped at least, when createView of a ViewHandler is called.



                • 5. Re: Custom PhaseListener timing
                  ryan dewell Novice

                  We built our application using Seam (beta 1) as an integral part. To that end, Seam participates fully in translating URLs into view selection / creation during GET requests.

                  For example, translating the URL:

                  /articles/db-driven-title.html

                  To perform this URL to view translation / setup, we access Seam components (including a managed persistence context) to determine what view to display (if any), and what to display in it.

                  Another example:

                  /action/do-something/

                  where "do-something" gets translated into a method call on a Seam component. This method call's outcome is then used to drive the view displayed for the GET request using regular NavigationHandler semantics.

                  There are really two points to perform this view selection in JSF. PhaseListeners as mentioned previously, OR more appropriate to the specification, a ViewHandler (createView).

                  Either way, the latest version of Seam does not appear to be "ready" to participate in translating custom URLs into views. For example, the conversation context is not setup until after createView is called.

                  In my previous post I hacked around SeamExtendedManagedPersistencePhaseListener to get it to startup a conversation before createView is called. But, this lead to other problems.

                  Should it be reasonable to consider that Seam components can participate in view selection / setup (createView)? We have some big decisions to make if not, because a great deal of our code is built around the Seam beta 1 notion of having components available earlier.

                  Ryan


                  • 6. Re: Custom PhaseListener timing
                    Gavin King Master

                    Isn't it best to use page actions for this?

                    • 7. Re: Custom PhaseListener timing
                      ryan dewell Novice

                      Hmm... I didn't realize the scope of the page actions framework. Maybe something like view-id="*" might work. Let me play around with that.

                      Ryan