2 Replies Latest reply on Jun 9, 2011 6:12 AM by Rob Shepherd

    Outject component instace in java code

    Alexei R Newbie

      Hello, can I outject some component o other object instance by using the seam api, Some like this




      Component.getInstance("mycomponent");



      but outjecting


      Thanks.

        • 1. Re: Outject component instace in java code
          omid pourhadi Apprentice

          I don't know what your need exactly is but for outjecting a component usually use @Out annotation and
          sometimes i use @Unwrap annotation to load a specific entity




          @Name("service")
          public class Service {
          
             @In 
             EntityManager em;   
          
             @Unwrap
             public YourEntity getYourEntity(){
                return em.createQuery().getSingleResult();
             }
          
          }
          



          Use in other Bean




          @In("#{service}")
          YourEntity yourentity
          




          • 2. Re: Outject component instace in java code
            Rob Shepherd Newbie

            For the Session scope you can do the following:




            String myContextVarName = "myContextVarName";
            Object mySessionObject = new Object();
            
            if(  Contexts.isSessionContextActive() )
            {
                Contexts.getSessionContext().set(myContextVarName, mySessionObject);
            }
            else
            {
                // oops no session yet.
            }