8 Replies Latest reply on Apr 25, 2007 9:21 AM by anescu

    Injection issue

    monkeyden

      Can anyone tell me why this doesn't work?

      Injector:

      @In(required = false, create = true)
      @Out(required = false, scope = SESSION)
      private DefaultPaginator paginator;
      
      @Factory("paginator")
      public void loadDefaultPaginator() {
       System.out.println("Loaded the paginator");
       paginator = (DefaultPaginator) Component.getInstance("paginator");
      }



      Injectee:
      @Name("paginator")
      @Scope(SESSION)
      public class DefaultPaginator implements Paginator {
       public DefaultPaginator() {}
      }


      I get hundreds of the System.out message before it finally dies with a StackOverflowError.

        • 1. Re: Injection issue
          christian.bauer

          The @Factory method is not necessary. And I don't think what you think it does is what it is actually for.

          • 2. Re: Injection issue
            monkeyden

             

            The @Factory method is not necessary.


            This was the next thing I tried after normal @In(create=true) didn't work.

            And I don't think what you think it does is what it is actually for.

            Care to enlighten me? Given the definition below, I thought I was using it correctly.

            Marks a method as a factory method for a context variable. A factory method is called whenever no value is bound to the named context variable, and is expected to initialize the value of the context variable.


            • 3. Re: Injection issue
              pmuir

              At the very least you are confusing Seam by providing two ways to initialise your paginator (a component and a factory). required=false,create=true doesn't make sense to me

              • 4. Re: Injection issue
                monkeyden

                Given that the component does not exist on first access, I would like it to be created, injected and save it to session. So how do you suggest it be annotated? The component itself looks correct, I assume.

                • 5. Re: Injection issue
                  pmuir

                  @In(create=true) - if it does exist in scope it will be injected, if it doesn't exist it will be created and injected

                  • 6. Re: Injection issue
                    monkeyden

                    Yeah, I tried that. It didn't work, which is what made me wonder about the requirements of the injected component. I always thought that the injected component just needed a @Name and a no-arg constructor, and Seam would handle the rest (Component.getInstance, I presume).

                    Caused by: org.jboss.seam.RequiredException: In attribute requires value for component: advancedSearchAction.paginator

                    • 7. Re: Injection issue
                      monkeyden

                      Can someone at least confirm that these are the base requirements to be able to inject a component? A simple JavaBean should work shouldn't it? The tutorial doesn't explicitly say what is necessary, and my bean doesn't appear to be any different than what I've seen injected in there.

                      • 8. Re: Injection issue

                        Hi,

                        I got the same error.
                        If I put just

                        @In(create = true)
                        UserHome lastUpdatedBy;

                        I get an exception about not-null value for that component (when some other's component list is called - a component reffering the first one)
                        If I put
                        @In(required = false, create = true)
                        UserHome lastUpdatedBy;

                        I get an exception latter when I try to "add" a new object.
                        More specific in the wire() method lastUpdatedBy is null and I get a NullPointerException.