3 Replies Latest reply on Jan 21, 2011 6:34 AM by antibrumm.mfrey0.bluewin.ch

    Dynamically populate Rich ComboBox with data in the Table

    olasamuel
      Hi All,

      I have already posted this to the JBoss richfaces community but could not get any answer and I was told to post it in the seam community. OK this is the problem.

      I have this entity Bean and I have a little .xhtml file. I want my combobox to fetch value from the table and display these value so that user can select it. My combobox show but disply no value from the table. Can somebody tell me what I am doing wrong. I will appreciate if there can be any help on this please.

      Below are the entity bean and the .xhtml file


      package admin.session

      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.List;
      import javax.persistence.CascadeType;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.GeneratedValue;
      import javax.persistence.OneToMany;
      import javax.persistence.Table;
      import org.hibernate.validator.Email;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.annotations.Name;



      @Entity
      @Table(name="subscriber")
      @Name("subscriber")
      public class Subscriber extends SubscriberModel implements Serializable{

           private static final long serialVersionUID = -8523083947739598497L;
           private Long id;
          private String subscriberName;
          private String subscriberDescription;
          private String contactPerson;
          private String telephoneNumber;
          private String cellphone;
          private String postalAddress;
          private String postalCode;
          private String businessAddress;
          private String postalCode1;
          private String email;
          private List<SubscriberRep> subscriberReps = new ArrayList<SubscriberRep>();
         
           
         
          @Id
          @GeneratedValue
          public Long getId(){
               return id;
          }
         
          public void setId(Long id){
               this.id = id;
          }
         
          @NotNull
          @Length(max = 40)
          public String getSubscriberName() {
               return subscriberName;
          }
         
         
          public void setSubscriberName(String subscriberName) {
               this.subscriberName = subscriberName;
          }
         
         
          @NotNull
          @Length(max = 100)
          public String getSubscriberDescription() {
               return subscriberDescription;
          }
         
         
          public void setSubscriberDescription(String subscriberDescription) {
               this.subscriberDescription = subscriberDescription;
          }
         
         
          @NotNull
          @Length(max = 30)
          public String getContactPerson() {
               return contactPerson;
          }
         
         
          public void setContactPerson(String contactPerson) {
               this.contactPerson = contactPerson;
          }
         
          @NotNull
          @Length(max = 15)
          public String getTelephoneNumber() {
               return telephoneNumber;
          }
         
         
          public void setTelephoneNumber(String telephoneNumber) {
               this.telephoneNumber = telephoneNumber;
          }
         
         
          @NotNull
          @Length(max = 15)
          public String getCellphone() {
               return cellphone;
          }
         
         
          public void setCellphone(String cellphone) {
               this.cellphone = cellphone;
          }
         
         
          @NotNull
          @Length(max = 100)
          public String getPostalAddress() {
               return postalAddress;
          }
         
         
          public void setPostalAddress(String postalAddress) {
               this.postalAddress = postalAddress;
          }
         
         
          @NotNull
          @Length(max = 6)
          public String getPostalCode() {
               return postalCode;
          }
         
         
          public void setPostalCode(String postalCode) {
               this.postalCode = postalCode;
          }
         
         
          @NotNull
          @Length(max = 100)
          public String getBusinessAddress() {
               return businessAddress;
          }
         
         
          public void setBusinessAddress(String businessAddress) {
               this.businessAddress = businessAddress;
          }
         
         
          @NotNull
          @Length(max = 6)
          public String getPostalCode1() {
               return postalCode1;
          }
         
         
          public void setPostalCode1(String postalCode1) {
               this.postalCode1 = postalCode1;
          }
         
          @NotNull
          @Email
          public String getEmail() {
               return email;
          }
         
         
          public void setEmail(String email) {
               this.email = email;
          }
         
          //@OneToMany(mappedBy="subscriber", cascade=CascadeType.ALL)
          @OneToMany(mappedBy="subscriber", cascade=CascadeType.ALL) //Just Added
          public List<SubscriberRep> getSubscriberReps() {
               return subscriberReps;
          }
         
          public void setSubscriberReps(List<SubscriberRep> subscriberReps) {
               this.subscriberReps = subscriberReps;
          }
         
         
          @Override
           public boolean equals(Object obj) {
                if (obj == null) {
                return false;
                
                }
                
                if (getClass() != obj.getClass()) {
                     return false;
                }
                
                final Subscriber other = (Subscriber) obj;
                if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
                     return false;
                }
                
                return true;
           }
         
          @Override
           public int hashCode() {
                int hash = 5;
                hash = 41 * hash + (this.id != null ? this.id.hashCode() : 0);
                hash = 41 * hash + (this.subscriberName != null ? this.subscriberName.hashCode() : 0);
                return hash;
           }
         
         
         
         
      }




                 <rich:panel>
                      <h:panelGrid columns="2">
                      <s:decorate id="selectUserDecoration" template="layout/edit.xhtml">
                        <ui:define name="label">Select Subscriber:</ui:define>
                        <h:selectOneMenu>
                        <s:selectItems Value="#{name}" var="subscriber" label="#{subscriber.SubscriberName}"
                                             itemValue="#{subscriber.subscriberName}" noSelectionLabel="Please Select..."/>

                         <s:convertEntity /> 
                        </h:selectOneMenu>
                      </s:decorate>
                     
                      </h:panelGrid>
                  </rich:panel>