1 Reply Latest reply on May 30, 2010 7:21 PM by kragoth

    how to access one seam component in to another seam component

    shwetank


      
      
      
      
      Hi Here is my components :
      
      EventBean:
      
      @Stateful
      @Name("eventBean")
      @Scope(ScopeType.CONVERSATION)
      public class EventBean implements DropListener ,EventBeanIn {
              
              
              public void processDrop(DropEvent dropEvent) {
                      System.out.println(dropEvent);
                      Dropzone dropzone = (Dropzone) dropEvent.getComponent();
                      
                      System.out.println(dropEvent.getDragValue());
                      System.out.println(dropzone.getDropValue());
                      manageUserAction.move(dropEvent.getDragValue(), dropzone.getDropValue());
              }
              
              @Remove
              public void destroy() {
              }
      }
      
      ManageUserAciton:
      
      
      @Stateful
      @Name("manageUserAction")
      @Scope(ScopeType.CONVERSATION)
      public class ManageUserAction implements ManageUserActionIn {
      
                  
              
              public void move(Object drag, Object drop){
                      
             System.out.print(drag);
                      System.out.print("shwetank");
                      System.out.print(drop);
                      
              }
      
              
      }
      
      
      Thanks 
      Shwetank sharma
      
      
      
      



        • 1. Re: how to access one seam component in to another seam component
          kragoth

          Hi Shwetank,


          Please take the time to read the Seam documentation. The question you are asking is talked about very early on in the documentation.


          There are multiple ways to access a Seam component inside another Seam component.


          The most common way to do this is using the '@In' annotation.


          @Stateful
          @Name("eventBean")
          @Scope(ScopeType.CONVERSATION)
          public class EventBean implements DropListener ,EventBeanIn {
          
              @In(value="manageUserAction") //The value comes from the NAME of the other Seam Component
              private ManageUserAction mua;
          
          }
          



          Another way you can do it is like this:


          public void processDrop(DropEvent dropEvent) {
               ManageUserAction mua = Component.getInstance("manageUserAction");
          }
          



          Never use the new operation on a Seam bean. If you use the new operator on a Seam bean you will not get the benefits of the Seam infrastructure on that instance. (Events, transactions etc).


          But, ultimately, you really need to take the time to read the Seam documentation and look at the Seam examples provided in the /examples directory of the Seam download. It is always a good idea to at least read the documentation before posting on the forums. :)


          Seam Doco