8 Replies Latest reply on Apr 27, 2006 12:46 PM by Gavin King

    Not understanding @Out completely

    Chad Arimura Newbie

      I have an entity bean named "member" to represent a user of our system. When a user logs in, the member is stored to a context variable:

      @In @Out
      private Member member;

      and accessed from jsf like this: #{member.first_name}

      Now I want to store another member to a context variable and display that users details like this: #{otherMember.first_name}

      Shouldn't the code look like this?

      @Out (value="otherMember")
      private Member otherMember;

      But this doesn't work...nothing shows up for #{otherMember.first_name}

      What am I doing wrong?


        • 1. Re: Not understanding @Out completely
          Chad Arimura Newbie

          anybody? even a point in the right direction so I can figure out how to do it myself would help....

          • 2. Re: Not understanding @Out completely
            Gavin King Master

            Perhaps you need scope=ScopeType.CONVERSATION ?

            • 3. Re: Not understanding @Out completely
              Gavin King Master

              By the way, you absolutely did not show enough code to make it possible to answer your question.

              • 4. Re: Not understanding @Out completely
                Chad Arimura Newbie

                Sorry... I thought maybe the problem was obvious enough to avoid posting code. I can't get the jsp file to display the users name if I try and use "otherMember" but it works fine if I change the bean and outputText tag to "member".

                Here's the bean:

                package org.cnow.site;
                import static javax.persistence.PersistenceContextType.EXTENDED;
                import static org.jboss.seam.annotations.Outcome.REDISPLAY;
                import java.io.Serializable;
                import javax.ejb.Interceptors;
                import javax.ejb.Remove;
                import javax.ejb.Stateful;
                import javax.faces.context.FacesContext;
                import javax.persistence.EntityManager;
                import javax.persistence.PersistenceContext;
                import org.jboss.seam.annotations.Begin;
                import org.jboss.seam.annotations.Conversational;
                import org.jboss.seam.annotations.Destroy;
                import org.jboss.seam.annotations.In;
                import org.jboss.seam.annotations.Name;
                import org.jboss.seam.annotations.Out;
                import org.jboss.seam.annotations.RequestParameter;
                import org.jboss.seam.ejb.SeamInterceptor;
                import org.cnow.object.Member;
                public class MemberDetailAction implements MemberDetail, Serializable
                 private EntityManager em;
                 private transient FacesContext facesContext;
                 int id;
                 @Out (value="otherMember")
                 private Member otherMember;
                 public String getDetails() {
                 otherMember = (Member)em.createQuery("from Member where id = :id")
                 .setParameter("id", id)
                 return "member_detail";
                 @Destroy @Remove
                 public void destroy() {}

                And here is the jsp view file:

                <%@ include file="/WEB-INF/inc/initializers.jspf" %>
                <c:set var="pagetitle" scope="request" value="Member Detail"/>
                <%// include file="/WEB-INF/inc/checkLogin.jspf" %>
                 <%@ include file="/WEB-INF/inc/head-main.jspf" %>
                 <div id="content">
                 <%@ include file="/WEB-INF/inc/header.jspf" %>
                 <div id="main-container">
                 <h1>Member Detail</h1>
                 <br /><br />
                 Name: <h:outputText value="#{otherMember.first_name} #{otherMember.last_name}"/><br>
                 <%@ include file="/WEB-INF/inc/footer.jspf" %>

                And finally, here's the Member object entity bean:

                package org.cnow.object;
                import static org.jboss.seam.ScopeType.SESSION;
                import java.io.Serializable;
                import java.util.Collection;
                import java.util.Date;
                import javax.persistence.CascadeType;
                import javax.persistence.Entity;
                import javax.persistence.FetchType;
                import javax.persistence.GeneratedValue;
                import javax.persistence.Id;
                import javax.persistence.OneToMany;
                import javax.persistence.OneToOne;
                import javax.persistence.Table;
                import org.hibernate.annotations.Where;
                import org.hibernate.validator.Length;
                import org.hibernate.validator.Email;
                import org.jboss.seam.annotations.Name;
                import org.jboss.seam.annotations.Scope;
                public class Member implements Serializable
                 private int id;
                 private String first_name;
                 private String last_name;
                 private String email;
                 private String address_1;
                 private String address_2;
                 private String city;
                 private String state;
                 private String zip_code;
                 private String phone;
                 private String password;
                 private boolean receive_newsletter;
                 private Date birthdate;
                 private int referred_by;
                 private char gender;
                 private Date joined_date;
                 private int campaign_id;
                 private Collection<MemberImage> member_images;
                 public Member(int id, String first_name, String last_name, String email, String password) {
                 this.id = id;
                 this.first_name = first_name;
                 this.last_name = last_name;
                 this.email = email;
                 this.password = password;
                 public Member() {}
                 @Id @GeneratedValue
                 public int getId() {
                 return id;
                 public void setId(int id) {
                 this.id = id;
                 @Length(min=1, message="Please provide your first name")
                 public String getFirst_name() {
                 return first_name;
                 public void setFirst_name(String first_name) {
                 this.first_name = first_name;
                 public String getLast_name() {
                 return last_name;
                 public void setLast_name(String last_name) {
                 this.last_name = last_name;
                 public String getEmail() {
                 return email;
                 public void setEmail(String email) {
                 this.email = email;
                 public String getAddress_1() {
                 return address_1;
                 public void setAddress_1(String address_1) {
                 this.address_1 = address_1;
                 public String getAddress_2() {
                 return address_2;
                 public void setAddress_2(String address_2) {
                 this.address_2 = address_2;
                 public String getCity() {
                 return city;
                 public void setCity(String city) {
                 this.city = city;
                 public String getState() {
                 return state;
                 public void setState(String state) {
                 this.state = state;
                 public String getZip_code() {
                 return zip_code;
                 public void setZip_code(String zip_code) {
                 this.zip_code = zip_code;
                 public String getPhone() {
                 return phone;
                 public void setPhone(String phone) {
                 this.phone = phone;
                 // Figure out how to best validate this for use in both login and register
                 @Length(min=4, message="Password must be at least 4 characters.")
                 public String getPassword() {
                 return password;
                 public void setPassword(String password) {
                 this.password = password;
                 public boolean isReceive_newsletter() {
                 return receive_newsletter;
                 public void setReceive_newsletter(boolean receive_newsletter) {
                 this.receive_newsletter = receive_newsletter;
                 public Date getBirthdate() {
                 return birthdate;
                 public void setBirthdate(Date birthdate) {
                 this.birthdate = birthdate;
                 public int getReferred_by() {
                 return referred_by;
                 public void setReferred_by(int referred_by) {
                 this.referred_by = referred_by;
                 public char getGender() {
                 return gender;
                 public void setGender(char gender) {
                 this.gender = gender;
                 public Date getJoined_date() {
                 return joined_date;
                 public void setJoined_date(Date joined_date) {
                 this.joined_date = joined_date;
                 public int getCampaign_id() {
                 return campaign_id;
                 public void setCampaign_id(int campaign_id) {
                 this.campaign_id = campaign_id;
                 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="member")
                 public Collection<MemberImage> getMember_images() {
                 return member_images;
                 public void setMember_images(Collection<MemberImage> member_images) {
                 this.member_images = member_images;

                • 5. Re: Not understanding @Out completely
                  Chad Arimura Newbie

                  Is that sufficient?


                  • 6. Re: Not understanding @Out completely
                    Gavin King Master

                    What scope is otherMember supposed to be? At the moment it is event-scoped.

                    • 7. Re: Not understanding @Out completely
                      Chad Arimura Newbie

                      ack... I didn't realize that scope was an available attribute for the @Out annotation. Is there a more updated version of the seam docs online or an errata anywhere?

                      Problem solved, thanks Gavin.