2 Replies Latest reply on Jul 23, 2009 12:43 PM by Stuart Douglas

    How can I find a component's name?

    Bill Evans Newbie

      I have a seam component with several roles:


      @Name("alertFilter")
      @Scope(ScopeType.SESSION)
      @Roles({
               @Role (name="accountFilter",scope=ScopeType.SESSION),
               @Role (name="caseDetailsFilter",scope=ScopeType.CONVERSATION),
                @Role (name="detailsFilter",scope=ScopeType.CONVERSATION),
                @Role (name="rtMonitorFilter",scope=ScopeType.SESSION),
                @Role (name="blahBlahFilter",scope=ScopeType.SESSION)



      At run-time I want a way to evaluate an instance of this Object and tell me which of the Roles the Object is assigned to, if any.  Is there a way I can do this?


      I see that during initialization Seam builds a Map of ComponentDescriptor Objects.  Presumably, somewhere each instance of a Seam-owned Object must be attached to one of these ComponentDescriptors.  So, how do I at run-time get this information?


        • 1. Re: How can I find a component's name?
          Nikos Paraskevopoulos Novice

          Hello,


          I do not know how you can achieve what you are asking, or if ti is possible at all.


          However, if all you want to do is something like:


          String componentName = findItSomehow();
          if( "accountFilter".equals(componentName) ) {
            doThis();
          }
          else if( "caseDetailsFilter".equals(componentName) ) {
            doThat();
          }
          ...etc...
          



          Wouldn't it be more appropriate and clean to have an abstract base class with the core functionality and then concrete implementations, each having a single @Name?

          • 2. Re: How can I find a component's name?
            Stuart Douglas Master

            If you specify a create method with a single parameter of type Component you can get access to the name:



            
            public class MyComponent
            {
              String name;
              @Create
              public void create(Component component)
              {
                name=component.getName();
              }
            
            }