2 Replies Latest reply on Jan 9, 2008 12:00 PM by Felix Khazin

    Creating a simple selectOneMenu

    Felix Khazin Newbie


      I'm trying to use a selectOneMenu for a String property in an Entity. For example I have an entity with:

      private String status;

      Instead of using a textbox for users to fill in this field i'd like to use a drop down with values that I populate. So I created the following h:selectOneMenu:

      <s:decorate template="layout/edit.xhtml">
       <ui:define name="label">Status</ui:define>
       <h:selectOneMenu value="#{customerHome.instance.status}">
       <f:selectItem itemLabel="Active" itemValue="Active"/>
       <f:selectItem itemLabel="Inactive" itemValue="Inactive"/>

      This works fine for submitting of the form. The selected itemValue will end up in the database. But when I want to view the data the proper selectItem is never selected. I know for example that #{customerHome.instance.status} contains the string "Inactive" but the form shows "Active".

      Any ideas how to fix that?


        • 1. Re: Creating a simple selectOneMenu

          i think this should be possible using s:enumItem and s:convertEnum,
          but you should also consider using a java-enumeration at entity-bean level:

          public enum CustomerStatus {
           public String getLabel() {
           return this.name(); //return whatever name you wanna see

          then use this enum on your entity bean:
           public CustomerStatus getStatus() {
           return status;

          then make the enum values available in the pages via a factory:
          public class CustomerStatusFactory {
           public CustomerStatus[] getCustomerStatus() {
           return CustomerStatus.values();

          in your page, use the enum:
          <h:selectOneMenu value="#{customerHome.instance.status}">
           <s:selectItems value="#{customerStatus}" var="cus"
           noSelectionLabel="Please select" />
           <s:convertEnum />

          U may also checkout the examples\ui\src\org\jboss\seam\example\ui example (Person-entity)

          • 2. Re: Creating a simple selectOneMenu
            Felix Khazin Newbie

            Thank you very much for that answer. It works perfectly with your method.