2 Replies Latest reply on Nov 22, 2006 12:09 PM by Ning Zhao

    always got data model update error when enum happens in data

    Ning Zhao Apprentice

      I am modifying the booking example code and added a enum type Gender to the type User. Since then, registration never succeeded. Always got this message:

      "verify": Error during model data update.

      The code in the xhtml file:

      <div class="entry">
       <div class="label"><h:outputLabel for="gender">Gender:</h:outputLabel></div>
       <div class="input"><s:decorate>
       <h:selectOneMenu id="gender" value="#{user.gender}"
       required="true">
       <f:selectItem itemLabel="female" itemValue="0" />
       <f:selectItem itemLabel="male" itemValue="1" />
       </h:selectOneMenu>
       <br />
       </s:decorate></div>
       </div>
      


      And the enum type happens in the User class, but not any backing beans.

      Any solution/enlightenment would be highly appreciated.


      Best Regards,
      Ellen

        • 1. Re: always got data model update error when enum happens in
          Gavin King Master

          I suppose you need to use a JSF Converter.

          • 2. Re: always got data model update error when enum happens in
            Ning Zhao Apprentice

            Voila! Thanks for the hint and now it is working perfectly.

            My solution is based on hotchai's solution here:

            http://jroller.com/page/hotchai?entry=jsf_converter_for_jdk_1

            (I am using Seam 1.1 beta 2 and all the example source code are from Seam 1.1 beta 2 as well)

            The EnumConverter class can be used as it is, no need to modify and it simply works.

            Here is my Enum classes:

            public class User implements Serializable {
             // same as the booking sample
             public static enum Gender{
             FEMALE("female"), MALE("male");
             private String label;
            
             Gender(String label){
             this.label = label;
             }
            
             public String getLabel(){
             return this.label;
             }
             }
            
             public static enum Title {
             DR("Dr."), MS("Ms."), MR("Mr."), MRS("Mrs.");
             private String label;
            
             Title(String label) {
             this.label = label;
             }
            
             public String getLabel() {
             return this.label;
             }
             }
            }
            
            here is the code from backing bean:
            
            @Stateful
            @Scope(EVENT)
            @Name("register")
            public class RegisterBacking implements Register {
             //...
             private SelectItem[] titleItems;
             private SelectItem[] genderItems;
            
            //... same as the booking example
            public SelectItem[] getTitleItems() {
             this.titleItems = new SelectItem[Title.values().length];
             int i = 0;
             for (Title t : Title.values()) {
             this.titleItems[i++] = new SelectItem(t, t.getLabel());
             }
             return this.titleItems;
             }
            
             public SelectItem[] getGenderItems() {
             this.genderItems = new SelectItem[Gender.values().length];
             int i = 0;
             for (Gender g : Gender.values()) {
             this.genderItems[i++] = new SelectItem(g, g.getLabel());
             }
             return this.genderItems;
             }
            }
            
            The code in register.xhtml:
            
            <div class="entry">
             <div class="label"><h:outputLabel for="title">Title:</h:outputLabel></div>
             <div class="input"><s:decorate>
             <h:selectOneMenu id="title" value="#{guest.title}" required="true">
             <f:selectItems value="#{register.titleItems}" />
             </h:selectOneMenu>
             <br />
             </s:decorate></div>
             </div>
            
            <div class="entry">
             <div class="label"><h:outputLabel for="gender">Gender:</h:outputLabel></div>
             <div class="input"><s:decorate>
             <h:selectOneMenu id="gender" value="#{guest.gender}"
             required="true">
             <f:selectItems value="#{register.genderItems}" />
             </h:selectOneMenu>
             <br />
             </s:decorate></div>
             </div>