11 Replies Latest reply on Mar 9, 2007 10:46 PM by monkeyden

    Inject messages into JavaBean

    monkeyden

      Trying to inject a map (messages) into my JavaBean (not a SB). Is this code possible? For that matter, @Logger doesn't work either.

      @Name("paginator")
      @Scope(SESSION)
      public class DefaultPaginator implements Paginator {
       @Logger
       private Log log;
      
       @In private Map<String, String> messages;
      
       @In("#{messages['paginator.linktext.prev']}")
       private String previous;
      
       @In("#{messages['paginator.linktext.next']}")
       private String next;
      
      ...
      
      }
      


        • 1. Re: Inject messages into JavaBean
          monkeyden

          BTW, all the values are null. I'm guessing I need to add these to components.xml. I also have this:

          <core:resource-bundle>
           <core:bundle-names>
           <value>messages</value>
           </core:bundle-names>
          </core:resource-bundle>


          in the components.xml (I know it's the default but it was worth a desperate try)

          I didn't see anything about the logger in the schema, so I assume that's not needed here.

          • 2. Re: Inject messages into JavaBean
            gavin.king

            How do you instantiate DefaultPaginator?

            • 3. Re: Inject messages into JavaBean

               

              "monkeyden" wrote:
              Trying to inject a map (messages) into my JavaBean (not a SB). Is this code possible? For that matter, @Logger doesn't work either.
              ...

              All that is possible. Ensure that your messages.properties is in the appropriate location (usually WEB-INF/classes). Then make sure your Log type is of org.jboss.seam.log.Log (not the commons version). Seam should then add the necessary magic to get it to work properly.

              • 4. Re: Inject messages into JavaBean
                monkeyden

                 

                How do you instantiate DefaultPaginator?

                By way of a constructor. Do I need to inject it instead, to make use of some Seam recursive injection facility?

                Ensure that your messages.properties is in the appropriate location (usually WEB-INF/classes)

                Yep, i18n works with EL in session beans and facelets.

                ...make sure your Log type is of org.jboss.seam.log.Log (not the commons version)

                Yep, it's a Seam Log.


                Here is the signature:

                public DefaultPaginator(String name, PageProvider owner, List keySet, int rowsPerPage)


                owner - the owner of the paginator. Implements callbacks for the paginator to use to load, as objects, subsets of keySet.

                name - the unique identifier of the paginator, in case there is more than 1 in a single Action. Used when the paginator calls:

                owner.loadPage(String name, List keys)

                List - complete list of primary keys

                I'll check out injection of it and call mutators for everything.





                • 5. Re: Inject messages into JavaBean

                   

                  "monkeyden" wrote:
                  How do you instantiate DefaultPaginator?

                  By way of a constructor. Do I need to inject it instead, to make use of some Seam recursive injection facility?


                  The bean is a seam-managed bean (you are using @Name) so you'll lose all the benefits that come with Seam if you instantiate it manually. May try using Component.getInstance() to construct it instead of using the new operator.

                  • 6. Re: Inject messages into JavaBean
                    monkeyden

                    Ok, I tried that, to no avail. What are the requirements of a POJO to allow it to be injected? I already have a no-arg.

                    • 7. Re: Inject messages into JavaBean
                      monkeyden

                      Can anyone tell me the minimum requirements of a custom component to allow it to be injected into another? I thought it was just:

                      no-arg constructor
                      A @Name annotation with a unique value

                      That didn't seem to work.

                      • 8. Re: Inject messages into JavaBean
                        pmuir

                        Post the code you are using to instatiate the seam component

                        • 9. Re: Inject messages into JavaBean
                          monkeyden

                          Im not instantiating it. I want Seam to create it and inject it.

                          To be injected

                          @Name("paginator")
                          @Scope(SESSION)
                          public class DefaultPaginator implements Paginator {
                          
                           @Logger
                           private Log log;
                          
                           public DefaultPaginator() {}
                          
                           ...business methods
                          
                          }


                          In the owner class
                          @Stateful
                          @Name("zipSearchRef")
                          @Scope(SESSION)
                          public class ZipSeachActionRef implements ZipSeachRef{
                          
                           @In(value="zipPaginator", create=true)
                           @Out(value="zipPaginator", scope=SESSION, required=false)
                           DefaultPaginator zipPaginator;
                          
                           ...business methods
                          
                          }


                          • 10. Re: Inject messages into JavaBean
                            pmuir

                            I don't see a component or factory for zipPaginator there... Remember Seam bijects on variable name, not class type

                            • 11. Re: Inject messages into JavaBean
                              monkeyden

                              I wonder where I got the idea that Seam would either find it in the specified context or call the no-arg constructor for me.