3 Replies Latest reply on Feb 15, 2010 3:38 AM by dish13

    Outjection problem. Sometimes evaluates to null

    dish13

      I have a component component CustomerActionBean this bean has a property customer that is annotated with @Out:


      @Out
              private Customer customer = new Customer();



      The component does not have a scope defined and In understand that the default is the conversation scope. I have a @Begin and @End annotated methods in CustomerActionBean but I do not invoke explicitly.


      I use this component in customer.xhtml page like:


             <h:inputText value="#{customer.name}" />
      



      I enter the URL for the customer.xhtml page in the browser and everything is displayed correctly.


      But I try the same for another component AddressActionBean the EJB is exactly the same except that instead of customer I have the address component:



      @Out
              private ServiceAddress serviceAddress = new ServiceAddress();




      Then I have in my address.xhtml page:


             <h:inputText value="#{serviceAddress.street}" />
      



      But if I try to go to the address.seam page instead of customer.seam I get an error saying:


      Target Unreachable, identifier 'serviceAddress' resolved to null




      To verify I placed the exact same code from my customer.xhtml page in the address.xhtml page and then I get:


      Target Unreachable, identifier 'customer' resolved to null



      I do not understand why in one page everything displays correctly then another one with the exact same code it doesn't.


      When I go to the address.seam page isn't it supposed to start a temporary conversation? Why does it evaluate to null?


        • 1. Re: Outjection problem. Sometimes evaluates to null
          niox.nikospara.yahoo.com

          Hello,


          I might be wrong, but if the component that @Outjects something is not created, the something will not be outjected! Make sure that the components do exist when the EL is called. As an alternative, you can use the factory pattern, implemented by Seam, that will ensure that the required outjected thing is always there.


          Unrelated to that, initializing a member field inline (i.e. @Out private Customer customer = new Customer();) has a side effect. When Seam creates the proxy object for your component, it will inevitably create an extra Customer. This is problematic if Customer is heavyweight or has side-effects. Initializing stuff in a constructor will result in the same potential proble.


          It is much better to initialize member fields in @PostConstruct (or Seam's equivalent @Create) methods.

          • 2. Re: Outjection problem. Sometimes evaluates to null
            blabno

            This is very simple, but you follow wrong trail which confuses you.
            Outjection happens after you call method on action bean. If you just enter the page (without page actions touching that action bean) then no outjection happens.


            The reason why you have Customer and not ServiceAddress is because Customer is seam component (i bet) and ServiceAddress is not. So even if there is no outjection, seam component gets instantiated if called by JSF.

            • 3. Re: Outjection problem. Sometimes evaluates to null
              dish13

              Yes, I noticed that if I that problem occurred when I called the outjected property without calling the action bean before (probably because the bean is not instantiated).


              Thank you.