1 Reply Latest reply on Apr 22, 2009 7:33 AM by nickarls

    Should f:selectItem be used with s:selectItems and s:convertEntity?


      <h:selectOneListbox value="#{addDepartmentForm.country}" size="1" id="country">
          <f:selectItem itemValue="-1" itemLabel=""/>
          <s:selectItems value="#{countries.allCountries_Dropdown}" var="c" label="#{c.name}"/>
          <s:convertEntity/>
      </h:selectOneListbox>




      @Name("addDepartmentForm")
      @Scope(ScopeType.EVENT)
      public class AddDepartmentForm implements Serializable {
          private Country country;
          // ... getters & setters
      }




      @Name("countries")
      @Scope(ScopeType.PAGE)
      public class Countries implements Serializable {
          @In private EntityManager entityManager;
          public List<Country> getAllCountries_Dropdown() {
              return entityManager.createQuery("select c from Country c").getResultList();
          }
      }




      @Entity
      @Table(name="COUNTRIES")
      public class Country {
          @Id
          @Column(name="COUNTRY_ID")
          private String id;
      
          @Column(name="COUNTRY_NAME")
          private String name;
          // ... getters & setters
      }



      If you look at the code, you'll see that I want to have a drop-down list of countries with a blank item on the top (so I need f:selectItem).The entity Country has a string id. But if I have a string value (which cannot be converted to a number) for the itemValue of the f:selectItem, I get a NumberFormatException for that non-number itemValue. Right now, I have to put a number there (which doesn't make sense, but doesn't cause exceptions).


      What's the right way to add a blank item on the top of the drop-down list like mine?


      Thank you.