2 Replies Latest reply on Jul 21, 2008 10:51 AM by Yann Laviolette

    Combo-box -=- Returning the appropriate ID or getting object

    Yann Laviolette Newbie

      Hi all!

      I'm searching for two days how to use the RichFaces Combo-box but I can't find how to use it properly...

      I must use a combo box to store a country list. Here's an example for the value list:

      Key Value
      1 Canada
      2 United States
      3 France

      I want to use a combo box and be able to return the key or something else (maybe the object itself!) to be able to store the relation in the database. I'm able to use the JSF combo box but I prefer the Richfaces one.

      Here's my code:


      inscription.jsp

      <rich:comboBox binding="#{inscriptionBean.box2}"
       immediate="true" id="box" value="#{inscriptionBean.enterpriseCountry}"
       suggestionValues="#{countryBean.countries}"
       directInputSuggestions="true"
       defaultLabel="Sélectionner un pays">
      </rich:comboBox>
      


      InscriptionBean.java
       private HtmlComboBox box2;
       private String enterpriseCountry;
       ...
      /**
       * @return the box
       */
       public HtmlComboBox getBox2() {
      
       return box2;
       }
      
       /**
       * @param box the box to set
       */
       public void setBox2(HtmlComboBox box) {
       this.box2 = box;
       }
      
      /**
       * @return the enterpriseCountry
       */
       public String getEnterpriseCountry() {
       return enterpriseCountry;
       }
      
       /**
       * @param enterpriseCountry
       * the enterpriseCountry to set
       */
       public void setEnterpriseCountry(String enterpriseCountry) {
       this.enterpriseCountry = enterpriseCountry;
       }
      
      
      public String submit() {
       Logger l = CoreLogger.getCoreGuiLogger();
      
       Enterprise enterprise = new Enterprise();
       enterprise.setName(enterpriseName);
      
       // Address
       enterprise.setCivicNumber(enterpriseCivicNumber);
       enterprise.setUnit(enterpriseUnit);
       enterprise.setPoBox(enterprisePoBox);
       enterprise.setStreet(enterpriseStreet);
       enterprise.setCity(enterpriseCity);
      
       //l.info(enterpriseCountry);
      
       l.info(box2.getAttributes().size());
      
       l.info((String)box2.getRowData());
      ...
      
      


      CountryBean.java
      
       /**
       * @return the countries
       */
       public ArrayList<String> getCountries() {
       countries = new ArrayList<String>();
      
       countries.add("CANADA");
       countries.add("USA");
      
      
      
      
      
       return countries;
       }
      
      
       public void setCountries(ArrayList<String> countries) {
       this.countries = countries;
       }
       ...
      
      }
      


      I'm only able to retreive the value but I need the ID or something unique...

      How can I do that? Any ideas?

      Thanks for you help!

      Yann