0 Replies Latest reply on May 20, 2010 5:52 PM by Sean Li

    2.2.1.CR1 EntityQuery bug?

    Sean Li Newbie

      I generated UserList.java(EntityQuery class) and UserList.xthml using seam generate-ui command, based on entity class: User.java.

      The problem is: when testing the search function in UserList.xhtml, I got the following error:

      WARN  [org.jboss.seam.Component] Cannot create Seam component, scope is not active: entityManager(CONVERSATION)

      I searched deeper into code and found this seems something inevitable.

      After 'Search's clicked, UserList.xhtml will go into JSF restore view phase. Since the page uses 'userList' component, the component needs to be created.

      When creating 'userList' component, it needs to call component's @Create method, which is validate(). In EntityQuery's validate method, it checks for entity manager, which is in conversation scope.

      The problem is, at that time, conversation context has not been created for the thread. Thus entity manager cannot be created. Exception throws.

      An interesting thing is, the conversation context is created just after that, in handleAfterPhase of restore view phase:


         protected void afterRestoreView(FacesContext facesContext)
            Map parameters = facesContext.getExternalContext().getRequestParameterMap();
            boolean conversationFound = Manager.instance().restoreConversation();
            FacesLifecycle.resumeConversation( facesContext.getExternalContext() );
            postRestorePage(facesContext, parameters, conversationFound);


         public static void resumeConversation(ExternalContext externalContext)
            ServerConversationContext conversationContext = new ServerConversationContext( externalContext.getSessionMap() );
            /*Context conversationContext = Init.instance().isClientSideConversations() ?
                  (Context) new ClientConversationContext() :
                  (Context) new ServerConversationContext( externalContext.getSessionMap() );*/
            Contexts.businessProcessContext.set( new BusinessProcessContext() );

      Have I missed anything? Or it's a bug?