7 Replies Latest reply on Jul 21, 2011 9:50 PM by Ro Chap

    A question about the sample code generated by Weld's JEE6 archetype

    Ro Chap Newbie

      In the generated app, there's a MemberRegistration bean that looks like this:


      @Model
      public class MemberRegistration {
          @Inject
          @Category("hello-weld-jee6")
          private Logger log;
      
          @Inject
          @MemberRepository
          private EntityManager em;
      
          @Inject
          private UserTransaction utx;
      
          @Inject
          private Event<Member> memberEventSrc;
      
          private Member newMember;
      
          @Produces
          @Named
          public Member getNewMember() {
              return newMember;
          }
      
          public void register() throws Exception {
              log.info("Registering " + newMember.getName());
              // UserTransaction only needed when bean is not an EJB
              utx.begin();
              em.joinTransaction();
              em.persist(newMember);
              utx.commit();
              memberEventSrc.fire(newMember);
              initNewMember();
          }
      
          @PostConstruct
          public void initNewMember() {
              newMember = new Member();
          }
      }



      Why the getNewMember() is not returning a RequestScoped instance instead? E.g.:


      @Produces
      @RequestScoped
      public Member getNewMember() {
        return new Member();
      }
      



      Thanks in advance.