4 Replies Latest reply on May 26, 2008 9:36 AM by stephen

    Access components in code

    frankyb

      Hi all,


      is there a way to receive an instance of an object that is registered as Seam component?


      To speak clearly, I am searching for a code snipped that has the same effect as


      @In("hibernateSession")
      Session session;





      I started with



      Component sessionComp = (Component)            Component.getInstance("hibernateSession.component");
      


      So I am able to receive the component as such. But how can I unwrap it to the class that it represents?



      Thanks in advance,


      Frank

        • 1. Re: Access components in code
          keithnaas

          The examples in the codebase and the docs show how to do this.


          31.2. Annotations displays an example


          Session session = (Session)            Component.getInstance("hibernateSession");



          The *.component names refer to the Seam internal objects.

          • 2. Re: Access components in code
            frankyb

            thank you, that's it!

            • 3. Re: Access components in code
              mattlc.mathieu.lecain.econexia.com

              Hi,


              I have a problem with this function. Whenever I call it, I get some classCastException.


              This is the way I call it :


              
              private PublicProductSearchBean getPublicProductSearchBean(){
              
                        return (PublicProductSearchBean) Component.getInstance("publicProductSearch",true);
              
                   }
              
              



              And the session bean declaration is :


              
              @Stateful
              
              @Name ("publicProductSearch")
              
              @Scope(ScopeType.SESSION)
              
              public class PublicProductSearchBean implements PublicProductSearch{ .... }
              
              



              I'm trying to implement web services. The seam doc says that this is the way to access business logic. And this is done exactly the same way in the seam 2.0.0GA (the version I use) seambay example.



              Any help ?

              • 4. Re: Access components in code
                stephen

                Cast to PublicProductSearch instead?!



                private PublicProductSearch getPublicProductSearchBean(){
                   return (PublicProductSearch) Component.getInstance("publicProductSearch",true);
                }