4 Replies Latest reply on Sep 3, 2008 8:31 AM by timerons

    Inject a POJO

    timerons

      hello


      we are running a nice application with seam :-)


      no we like to inject a pojo. this class is in a jar that is in the classpath. we do not want this to be annotated as ejb or a seam component.


      i try use @In but it was always null.


      i guess i have to declare it in a config file. but i do not know where.


      thx :-)

        • 1. Re: Inject a POJO
          mail.micke

          Hi


          Is the pojo annotated with Seam annotations?
          If it is there a seam.properties file in there so that it is scanned by Seam at startup?


          If the pojo is discovered as a Seam component you should be able to see this in the log when the server starts up.


          If not you could define the pojo as a bean in components.xml or in Spring or perhaps via faces-config.xml.


          - micke

          • 2. Re: Inject a POJO
            accless

            Seam can only inject/outject ejbs and pojos which are manageable and regocnized at startup of the web app.
            There are two (or even more ways) to inform seam about these manageable objects:



            • annotations

            • components.xml







            u have to use components.xml, if u cannot or do not want to recompile (using name-annotations) the target-class itself


            example



            <component name="someName" class="FULL_QUALIFIED_NAME_OF_THE_CLASS_U_WANT_TO_MAKE_MANAGABLE" auto-create="true" scope="EVENT" >
            </component>



            • 3. Re: Inject a POJO
              timerons

              thanks a lot that was what i looking for. i will test it and give you feedback. :-)

              • 4. Re: Inject a POJO
                timerons

                hello


                thanks this works well in a normal bean. thanks a lot for you help.


                now i like to use this bean the authenticator


                every thing work well except of the injection of the ldapServiceAuthenticate


                i did the following entry's in the components.xml:




                <security:identity authenticate-method="#{authenticator.authenticate}"/>
                <component name="ldapServiceAuthenticate" class="com.xxx.ldap.LdapServiceAuthenticate" auto-create="true" scope="application">





                in my beans i use the following:


                @In(create=true)
                private LdapServiceAuthenticate ldapServiceAuthenticate; 





                - in a normal bean i get the ldapServiceAuthenticate injected :-)


                - in my authenticator i let inject the LDAPService (work well), that get the ldapServiceAuthenticate injectet that is always null.




                other things work well when we like that to be injected:



                @Stateless
                @Name("authenticator")
                public class Authenticator implements IAuthenticator {
                        @In
                        Identity identity; 
                
                        @Out(required = false, scope = SESSION)
                        private User user;
                
                        @EJB
                        private IConfigurationDAO configDAO;
                        
                        @EJB
                        private IUserDAO userDAO;
                        
                        @EJB
                        private ILDAPService ldapService;
                        
                        @In
                        private FacesMessages facesMessages;









                @Stateless
                public class LDAPService implements ILDAPService {
                        
                        @In(create=true)
                        private LdapServiceAuthenticate ldapServiceAuthenticate; 








                that works well:



                @Stateful
                @Scope(ScopeType.CONVERSATION)
                @Name("productCreationCtrl")
                public class ProductCreationController implements IProductCreationController {
                
                        @In
                        private FacesMessages facesMessages;
                        
                        @In(create=true)
                        private LdapServiceAuthenticate ldapServiceAuthenticate; 
                






                may someone has a clue why i can't inject something in the Authenticator or better in the LDAPService


                best regards