3 Replies Latest reply on Apr 5, 2008 8:47 AM by dhinojosa

    Component creation: question on @Name and @Role

    fsat.f_satyaputra.yahoo.co.uk

      Hi All,


      I'd like to find out more about Component and Role.



      1. What is the difference between declaring @Name and declaring @Role? From reading docs chapter 3.2.9 my understanding is Seam treats them more or less the same way. Am I correct?




      1. If within a component instance, how can I find out whether the instance if declared using @Name or @Role along with the appropriate context variable?



      For example, if I have:


      @Name("mycomp")
      @Scope(ScopeType.CONVERSATION)
      @Roles({
          @Role(name="invitationFormElementTwo",
          scope=ScopeType.CONVERSATION),
          @Role(name="invitationFormElementThree", 
          scope=ScopeType.CONVERSATION)
      })
      public class InvitationFormElement extends BaseFormElement {
      // snip...
      }
      



      How can I tell if the current instance of InvitationFormElement is declared using which @Role or @Name?


      I suppose what I am trying to achieve in the end is trying to create few Components dynamically and trying to register them with Seam.


      I'd be really grateful if someone who has done this can share a hint or two.


      Thanks !


      Felix

        • 1. Re: Component creation: question on @Name and @Role
          dhinojosa

          1. Yes, they are multiple mappings
          2. I don't believe you can, and I can't see why that would be important.


          I think it would be best to rethink your design options in this case.  Can you make a InvitationManager object to manage the invitations?  Maybe a transient method in a model can handle this logic?


          I don't know what your code is, or what is its intent.  Something like this though screams for needing to rethink the problem.


          • 2. Re: Component creation: question on @Name and @Role
            fsat.f_satyaputra.yahoo.co.uk

            Thanks for the fast reply!


            I have a page where someone can send invitation to their friends to sign up.


            On that page there is a button called 'Add more friends'. When this button is clicked, a new sub form will be inserted. The sub form has textfields where the user can enter their friend's name and email address.


            The plan I have right now is to create a new Component for every new sub form.

            • 3. Re: Component creation: question on @Name and @Role
              dhinojosa

              Oh yeah sure, a good clean redesign is in order.  Just a rule of thumb, in any software/database design, if you find yourself naming things something1, something2, something3, something4 then you are are doing something wrong.



              @Name("invitation")
              @Scope(ScopeType.CONVERSATION)
              public class Invitation {
                  private String firstName;
                  private String lastName;
                  private String emailAddress;
              }
              
              @Name("inviteAction")
              @Scope(ScopeType.CONVERSATION)
              public class InviteAction {
                 @In @Out
                 private Invitation invitation;
              
                 public void addInvitation() {
                    //Here you can add the invite to a user account
                    //and save it or send the invite or 
                    //do whatever you want
                 }
              }