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

    Outject component instace in java code

    alexeicu

      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
          vata2999

          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
            robshep

            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.
            }