3 Replies Latest reply on Mar 6, 2007 4:43 PM by rlhr

    Weird behaviour with outjection

      Hello,

      I'm using jboss-seam-1.1.7.RC1 with jboss-4.0.5.GA.

      I have a SFSB defined as followed:

      @Stateful
      @Name("testAction")
      @Scope(ScopeType.CONVERSATION)
      public class TestAction implements Test {
      
       @In(create=true)
       private EntityManager entityManager;
      
       @RequestParameter
       private Long id;
      
      
       @Out(required=true)
       private User user = null;
      
       public String view() {
      
       // Retrieve user
       this.user = entityManager.find(User.class, this.id));
      
       return "home";
       }
      
       @Destroy
       @Remove
       public void destroy() {
       }
      
       /*
       * Getters and Setters
       */
      
       public User getUser() {
       return user;
       }
      
       public void setUser(User user) {
       this.user = user;
       }
      }
      


      In pages.xml, I have:

      <page view-id="/home.xhtml" action="#{testAction.view}">
       <begin-conversation />
      </page>
      


      Here is the strange behaviour:

      in /home.xhtml, if I directly use the user object as in #{user.name}, the value returned must be null (nothing shows up in the page).

      Now let say that the home page contains #{user.name}, #{user.phone} and #{user.email} in this order. If I change the second entry by #{testAction.user.phone}, I will get a value for the #{testAction.user.phone} but also for #{user.email} (but still not for #{user.name}).

      So it looks like the user object is not outjected until the el expression #{testAction.user.phone} is called.

      What is even more strange is that it seems to work fine in some other places I use outjection....

      Any idea?

      Richard

        • 1. Re: Weird behaviour with outjection
          pmuir

          is testAction.view called on page load? If so is user set in the method?

          • 2. Re: Weird behaviour with outjection

            It is called by clicking a link (<h:outputLink /> that call the page /home.xhtml.
            So I checked that the view method is properly called and the id of the user is properly passed, the user retrieved and set.

            The interesting thing is that I added a getTest() method to the SFSB that just return a string.
            If I call #{testAction.test} in the page, any further occurence of #{user.xxx} will work in the page. But any previous accurence will render nothing.

            So it seems that the user bean is not outjected until the page is rendered and an explicit call to a method of the SFSB is done in that particular case.
            I try to investigate to find out if there is anything different about what I do that leads to this strange behaviour.

            • 3. Re: Weird behaviour with outjection

              So I'm finally back to this issue and narrowed down the problem.

              I have 2 SFSB named testAction (defined in previous post) and anotherAction that actually outject the User bean.
              The scope of both SFSB is conversation and the outjection on both SFSB is defined as:

              @Out(required=true)
              private User user = null;
              


              In anotherAction SFSB, the outjection works fine. In the other one, the outjection is not done unless the xhtml file contains something like #{testAction.user.xxx}.

              Now if in the testAction is change the code as follow:

              @Out(required=true)
              private User user2 = null;
              


              And consequently use in my xhtml file #{user2.xxx}, everything is fine.

              This change works too:

              @Out(value="user2", required=true)
              private User user = null;
              


              So it looks like the problem comes from the fact that the 2 user bean are outjected under the same name.

              Since they are outjected in different conversations, why is this a problem?
              Is this a bug or is it not possible to outject bean under the same name?

              Thanks,

              Richard