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

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

    Thai Dang Vu Apprentice

      <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}"/>

      public class AddDepartmentForm implements Serializable {
          private Country country;
          // ... getters & setters

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

      public class Country {
          private String id;
          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.