0 Replies Latest reply on May 3, 2010 10:54 PM by jgurda

    s:convertEnum error message

    jgurda

      Hi friends,


      In my application I'm using s:enumConvert tag and I think there is a problem with this tag.


      My code looks like this:


      <h:selectOneMenu id="title_text_alignment" value="#{newPanel.titleAlignment}">
          <s:selectItems value="#{newPanelAction.titleAlignments}" var="alignment" label="#{alignment.description}" />
          <s:convertEnum/>
      </h:selectOneMenu>
      



      and I have Enum TitleAlignment:


      public enum TitleAlignment {
          LEFT("To left"), 
          RIGHT("To right"), 
          CENTER("To center");
      
          private final String description;
      
          private TitleAlignment(String description) {
           this.description = description;
          }
      
          public String getDescription() {
           return description;
          }
      }
      



      newPanelAction.titleAlignments returns:


      public TitleAlignment[] getTitleAlignments() {
          return TitleAlignment.values();
      }
      



      newPanel is simply object with field of type TitleAlignment (newPanel.titleAlignment).


      This code works fine, but problem appeares after modification of the HTML code in browser (for example in Firebug)


      This is oryginal code rendered from first listing:


      <select size="1" name="j_id39:title_text_alignment" id="j_id39:title_text_alignment" tabindex="0">     
          <option selected="selected" value="LEFT">To left</option>
          <option value="CENTER">To center</option>
          <option value="RIGHT">To right</option>
      </select>
      



      When I modify first option's value from LEFT to LEFTTTT and submit form, exception is thrown:


      java.lang.IllegalArgumentException: No enum const class com.example.model.enumeration.TitleAlignment.LEFTTTT
      



      It isn't validation exception and my application justs crashes, and error site is displayed. The only idea I have is to write my own converter with default conversion in case of exception but mayby there is another solution which I can't find. Do you have any solutions of this problem?