12 Replies Latest reply on Mar 6, 2007 4:30 AM by Kenneth Christensen

    @In(create = true) @Out works fine in 1.1.5.GA and not in 1.

    Kenneth Christensen Novice

       

      @Stateful
      @Name("accountBean")
      public class AccountBean implements AccountLocal {
       @PersistenceContext
       private EntityManager em;
      
       @In(create = true) @Out
       private User userDomain;
      
       @In(required = false)
       private Locale localeDomain;
      
       @Out(required = false)
       private Account accountDomain;
      
       @Begin
       public String begin() {
       return "accountCreateAgreement";
       }
      
       public String acceptDisclaimer() {
       userDomain.setDisclaimerAcceptDate(new Date());
      
       return "accountCreateForm";
       }
      
       public String validatePageRequest() {
       if ((userDomain != null) && (userDomain.isDisclaimerAccepted())) {
       return null;
       } else {
       return cancel();
       }
       }
      
       @End
       public String create() {
       if (!userDomain.isDisclaimerAccepted()) {
       return cancel();
       }
      
       try {
       em.createNamedQuery("user.findByUsername")
       .setParameter("username", userDomain.getUsername())
       .getSingleResult();
      
       // User exists
       FacesMessages.instance().addFromResourceBundle("username", FacesMessage.SEVERITY_ERROR, "usernameExists");
       return null;
       } catch (NoResultException e) { // Ignore
       } catch (NonUniqueResultException e) { } // Ignore - can never occur
      
       User user = UserType.MEMBER.getUserWithDependencies(this.userDomain);
       user.getUserSettings().setLocale(localeDomain);
      
       GregorianCalendar validToDate = new GregorianCalendar(localeDomain.getJavaLocale());
       validToDate.setTimeZone(TimeZone.getTimeZone(localeDomain.getTimeZone()));
       validToDate.set(GregorianCalendar.AM_PM, GregorianCalendar.AM);
       validToDate.set(GregorianCalendar.HOUR, 0);
       validToDate.set(GregorianCalendar.HOUR_OF_DAY, 0);
       validToDate.set(GregorianCalendar.MINUTE, 0);
       validToDate.set(GregorianCalendar.SECOND, 0);
       validToDate.set(GregorianCalendar.MILLISECOND, 0);
       validToDate.add(GregorianCalendar.DAY_OF_MONTH, 31);
      
       accountDomain = user.getAccount();
       accountDomain.setValidTo(validToDate.getTime());
      
       em.persist(user);
      
       // Encode password
       Md5PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
       user.setPassword(passwordEncoder.encodePassword(user.getPassword(), user.getId()));
      
       return "accountCreateWelcome";
       }
      
       @End
       public String cancel() {
       return "accountCreateCancel";
       }
      
       @Remove @Destroy
       public void destroy() {
       }
      }
      


      1.1.5.GA
      Seam creates one instance of userDomain and for each method call
      Seam injects the same instance of userDomain.

      1.2.0.PATCH1
      For each method call Seam creates a new instance of userDomain.

      Can anybody here tell me what's going on?

      Thanks,
      /Kenneth


        • 1. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
          Kenneth Christensen Novice

          Any help.... please :-)

          It's a really big problem for me, that Seam 1.2.0 creates a new instance of userDomain when an AccountBean method is invoked - for each AccountBean method call I get a new userDomain instance !

          Seam 1.1.5 creates one instance of userDomain and use this instance when an AccountBean method is invoked - for each AccountBean method call I get the same userDomain instance (this is the expected behaviour).

          Because of this I can't use Seam 1.2.0 for my application :-(

          • 2. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
            Juraj Holtak Newbie

            What is "userDomain"? (StatefullBean, StatelessBean,...)
            and what scope is it in? Use debug.seam to check if it is really there where you want it.

            I`ll check the @In (create=true) acting today when I come to coding but I`ve moved to 1.2PATCH1 from 1.1.5 and don`t have this problems.

            • 3. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
              Kenneth Christensen Novice

               

              "holtak" wrote:
              What is "userDomain"? (StatefullBean, StatelessBean,...)
              and what scope is it in? Use debug.seam to check if it is really there where you want it.

              I`ll check the @In (create=true) acting today when I come to coding but I`ve moved to 1.2PATCH1 from 1.1.5 and don`t have this problems.



              userDomain is an instance name for an EntityBean (User) and AccountBean is a StatefulBean with the scope CONVERSATION.

              I have debugged the code and can see that every time Seam 1.2.0 invokes a method on AccountBean a new instance of userDomain (User) is created and injected.
              But in Seam 1.1.5 only one userDomain (User) instance is created and this instance will be injected in every method call on AccountBean.

              I will try to debug some more and test it against Seam 1.1.6.


              • 4. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
                Kenneth Christensen Novice

                No comments/help from the people behind JBoss Seam?

                It's really strange, because I only replaced the 1.1.5 jar files (jboss-seam.jar and jboss-seam-ui.jar) with the 1.2.0 files.

                Have something changed in the @In @Out behaviour in 1.2.0 or/and in the bijection implementation?

                • 5. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
                  Gavin King Master

                  Nothing significant has changed, no.

                  No-one can help you if you havn't showed the code for UserDomain.

                  • 6. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
                    Kenneth Christensen Novice

                    Ok, I will do some more investigation :-)

                    User (userDomain):

                    @Entity
                    @Name("userDomain")
                    @Table(name = "userx") // user is a reserved word in PostgreSQL
                    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
                    @DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING)
                    @NamedQueries({
                     @NamedQuery(name = "user.findByUsername",
                     query = "select u from User u where u.username = :username")})
                    public class User implements Serializable {
                     private Long id;
                    
                     private String username;
                     private String password;
                     private String firstname;
                     private String lastname;
                     private String email;
                     private Address address;
                     private Account account;
                     private Set<Authority> authorities;
                    
                     // User settings
                     private UserSettings userSettings;
                    
                     // User type
                     private UserType type;
                    
                     // Disclaimer accept date
                     private Date disclaimerAcceptDate;
                    
                     public User() {
                     userSettings = new UserSettings();
                     }
                    
                     @Id
                     @GeneratedValue
                     public Long getId() {
                     return id;
                     }
                    
                     public void setId(Long id) {
                     this.id = id;
                     }
                    
                     @Column(unique = true, nullable = false)
                     public String getUsername() {
                     return username;
                     }
                    
                     public void setUsername(String username) {
                     this.username = username;
                     }
                    
                     @Column(nullable = false)
                     public String getPassword() {
                     return password;
                     }
                    
                     public void setPassword(String password) {
                     this.password = password;
                     }
                    
                     @Column(nullable = false)
                     public String getFirstname() {
                     return firstname;
                     }
                    
                     public void setFirstname(String firstname) {
                     this.firstname = firstname;
                     }
                    
                     @Column(nullable = false)
                     public String getLastname() {
                     return lastname;
                     }
                    
                     public void setLastname(String lastname) {
                     this.lastname = lastname;
                     }
                    
                     public String getEmail() {
                     return email;
                     }
                    
                     public void setEmail(String email) {
                     this.email = email;
                     }
                    
                     @Embedded
                     public Address getAddress() {
                     return address;
                     }
                    
                     public void setAddress(Address address) {
                     this.address = address;
                     }
                    
                     @OneToOne(cascade = CascadeType.ALL)
                     public Account getAccount() {
                     return account;
                     }
                    
                     public void setAccount(Account account) {
                     this.account = account;
                     }
                    
                     @ManyToMany(fetch = FetchType.EAGER)
                     @JoinTable(name = "user_authority", joinColumns = {@JoinColumn(name = "user_id")},
                     inverseJoinColumns = {@JoinColumn(name = "authority_id")})
                     public Set<Authority> getAuthorities() {
                     return authorities;
                     }
                    
                     public void setAuthorities(Set<Authority> authorities) {
                     this.authorities = authorities;
                     }
                    
                     @OneToOne(cascade = CascadeType.ALL)
                     public UserSettings getUserSettings() {
                     return userSettings;
                     }
                    
                     public void setUserSettings(UserSettings userSettings) {
                     this.userSettings = userSettings;
                     }
                    
                     public UserType getType() {
                     return type;
                     }
                    
                     public void setType(UserType type) {
                     this.type = type;
                     }
                    
                     @Column(name = "disclaimer_accept_date", nullable = false)
                     public Date getDisclaimerAcceptDate() {
                     return disclaimerAcceptDate;
                     }
                    
                     public void setDisclaimerAcceptDate(Date disclaimerAcceptDate) {
                     this.disclaimerAcceptDate = disclaimerAcceptDate;
                     }
                    
                     @Transient
                     public boolean isDisclaimerAccepted() {
                     return disclaimerAcceptDate != null;
                     }
                    
                     @Transient
                     public GrantedAuthorityImpl[] getGrantedAuthorities() {
                     int index = 0;
                    
                     GrantedAuthorityImpl grantedAuthorities[] = new GrantedAuthorityImpl[authorities.size()];
                     for (Authority authority : authorities) {
                     grantedAuthorities[index++] = new GrantedAuthorityImpl(authority.getAuthority());
                     }
                    
                     return grantedAuthorities;
                     }
                    
                     @Override
                     public String toString() {
                     StringBuffer sb = new StringBuffer();
                     sb.append("Username: ").append(username);
                     sb.append(", Firstname: ").append(firstname);
                     sb.append(", Lastname: ").append(lastname);
                    
                     return sb.toString();
                     }
                    }
                    
                    


                    • 7. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
                      Kenneth Christensen Novice

                      The behaviour for pages.xml have changed in 1.2.0 ! Because if I remove pages.xml everything will work out just fine.

                      pages.xml:

                      <!DOCTYPE pages PUBLIC "-//JBoss/Seam Pages Configuration DTD 1.1//EN" "http://jboss.com/products/seam/pages-1.1.dtd">
                      
                      <pages>
                       <page view-id="/xhtml/account/create/agreement.jspx" action="#{accountBean.begin}"/>
                       <page view-id="/xhtml/account/create/create.jspx" action="#{accountBean.validatePageRequest}"/>
                       <page view-id="/xhtml/account/create/welcome.jspx" action="#{accountBean.validatePageRequest}"/>
                      </pages>
                      


                      Something in pages.xml triggers the above problem (for each method call Seam creates a new instance of userDomain).


                      • 8. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
                        Juraj Holtak Newbie

                        Just loud thinking:

                        you always get a new (not nested) conversation with seam 1.2PATCH1 and then @In can`t inject the old instance? And this is not so when you move back to 1.1.5, for some reason...

                        Also, I don`t understand why do you return a String from #{acountBean.begin}? That makes things somewhat overcomplicated to me.

                        • 9. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
                          Kenneth Christensen Novice

                           

                          "holtak" wrote:
                          Just loud thinking:

                          you always get a new (not nested) conversation with seam 1.2PATCH1 and then @In can`t inject the old instance? And this is not so when you move back to 1.1.5, for some reason...


                          With 1.2.0 and pages.xml I get a new conversation id at each request for the current conversation and that's not correct because @In can`t inject the old instance, but for 1.1.5 and pages.xml I have the same conversation id throughout the conversation.

                          "holtak" wrote:

                          Also, I don`t understand why do you return a String from #{acountBean.begin}? That makes things somewhat overcomplicated to me.


                          Because my conversation consist of 3 pages (request).

                          Page 1) Disclaimer - accept yes or no (Conversation Begin)

                          Page 2) User enter personal data

                          Page 3) Welcome text

                          If a new user try to hit page 2 or page 3 without accepting the "Disclaimer" at page 1, then the conversation will end.

                          I return a String in #{acountBean.begin} to navigate to the right 'Begin' page (I'm using JSF navigation).

                          Maybe it's the wrong way to use Seam and page actions (from 1.2.0) but as I have mentioned earlier everything works just fine for 1.1.5 :-)


                          • 10. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
                            Kenneth Christensen Novice

                            Now it works :-)

                            Old pages.xml (OK for 1.1.5 and not OK for 1.2.0):

                            <!DOCTYPE pages PUBLIC "-//JBoss/Seam Pages Configuration DTD 1.1//EN" "http://jboss.com/products/seam/pages-1.1.dtd">
                            
                            <pages>
                             <page view-id="/xhtml/account/create/agreement.jspx" action="#{accountBean.begin}"/>
                             <page view-id="/xhtml/account/create/create.jspx" action="#{accountBean.validatePageRequest}"/>
                             <page view-id="/xhtml/account/create/welcome.jspx" action="#{accountBean.validatePageRequest}"/>
                            </pages>
                            


                            New pages.xml (OK for 1.2.0. Havn't tried it for 1.1.5):

                            <!DOCTYPE pages PUBLIC "-//JBoss/Seam Pages Configuration DTD 1.1//EN" "http://jboss.com/products/seam/pages-1.1.dtd">
                            
                            <pages>
                             <page view-id="/xhtml/account/create/create.jspx" action="#{accountBean.validatePageRequest}"/>
                             <page view-id="/xhtml/account/create/welcome.jspx" action="#{accountBean.validatePageRequest}"/>
                            </pages>
                            


                            For 1.2.0

                             <page view-id="/xhtml/account/create/agreement.jspx" action="#{accountBean.begin}"/>
                            


                            triggers a new conversation id for each request in the same conversation.

                            As mentioned earlier maybe it's not the correct way I have used page actions, but it's difficult to know, because it works just fine for 1.1.5 and not for 1.2.0 - maybe it have been a bug for Seam versions <1.1.5 (1.1.6) and the bug have been fixed for 1.2.0 or this is a new bug in 1.2.0?


                            • 11. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
                              Gavin King Master

                              I cannot reproduce this behavior. If a page action begins a conversation, everything works just fine for me.

                              • 12. Re: @In(create = true) @Out works fine in 1.1.5.GA and not i
                                Kenneth Christensen Novice

                                 

                                "gavin.king@jboss.com" wrote:
                                I cannot reproduce this behavior. If a page action begins a conversation, everything works just fine for me.


                                What can I say? Very odd :-)

                                But now it works fine for me and it also works fine for you, so everybody are happy :-)

                                Thanks for your time and help.