2 Replies Latest reply on Apr 28, 2006 11:16 AM by Gavin King

    Entity bean helper functions possible?

    Chad Arimura Newbie

      Is it possible to add a helper function to an Entity bean that is not a getter or setter?

      For example, are the two methods at the bottom of this code valid? If so, how do I display their values inside jsf? I tried #{member.getAge} but that didn't work....

      package org.cnow.object;
      
      import static org.jboss.seam.ScopeType.SESSION;
      
      import java.io.Serializable;
      import java.util.Calendar;
      import java.util.Collection;
      import java.util.Date;
      import java.util.GregorianCalendar;
      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.Table;
      import javax.persistence.Transient;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.Email;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      @Entity
      @Name("member")
      @Scope(SESSION)
      @Table(name="members")
      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;
       }
      
       @Email
       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;
       }
      
       /*
       public String getGenderString() {
       if (new Character(this.otherMember.getGender()).toString().equals("M")) {
       return "Male";
       } else {
       return "Female";
       }
       }
      
      
       public int getAge() {
       Calendar c1 = new GregorianCalendar();
       Calendar c2 = new GregorianCalendar();
       c1.setTime(this.otherMember.getBirthdate());
      
       int age = c2.YEAR - c1.YEAR;
      
       return age;
       }
       */
      }
      


      Thanks!