0 Replies Latest reply on Nov 23, 2009 11:39 AM by olibutzki.oliver_libutzki.gmx.de

    Enum from SelectOneMenu not persisted

    olibutzki.oliver_libutzki.gmx.de

      Hi everyone,


      I have problem persisting an enum type in the database after I have chosen it within a SelectOneMenu. The enum which is persisted always is null, although I selected a value.


      My enum (shortened):


      package com.example.util;
      
      public enum Day{
           MONDAY(1, "Monday"), TUESDAY(2, "Tuesday"));
      
           private String ivLabel = null;
           private int ivOridinal = 0;
      
      
           private Day(int aOrdinal, String aLabel) {
                ivOridinal = aOrdinal;
                ivLabel = aLabel;
           }
      
           public String getLabel() {
                return ivLabel;
           }
           
           @Override
           public String toString() {
                return getLabel();
           }
      
           public int getOridinal() {
                return ivOridinal;
           }
      
      }
      



      My entity (shortened):


      package com.example.entity;
      
      @Entity
      public class Time implements Serializable
      {
           @Enumerated(EnumType.STRING)
           private Day ivDay;
      
           @Enumerated(EnumType.STRING)
           public Day getDay() {
                return ivDay;
           }
      
           public void setDay(Day aDay) {
                ivDay = aDay;
           }
      }
      



      My action bean (shortened):


      package com.example.action;
      
      @Name("MyAction")
      public class MyAction
      {
          @DataModel
          private List<Time> ivTimes;
      
           @Factory(value = "days")
           public Day[] getDays() {
              return Day.values();
           }
      }
      



      My xhtml-page (shortened):


      <rich:dataTable id="editTable" var="item" value="#{ivTimes}">
                 
           <rich:column>
                <f:facet name="header">
                     <h:outputText value="Day"/>
                </f:facet>
                <h:selectOneMenu value="#{item.day}" id="day" required="false">
                     <s:convertEnum />
                      <s:selectItems hideNoSelectionLabel="true" value="#{MyAction.day}" var="day" label="#{day.label}"/>
                </h:selectOneMenu>
           </rich:column>
      </rich:dataTable >
      



      That's it. The values stored in the database for the attribute day are diplayed correctly, but after I have peristed my changes in the combo box all days are null in the database.


      Does anyona have an diea?


      Thank you so much in advance


      Oliver