title: Playframework! Using @select for a Enum property
body: <p>I'm trying to create a @select input for a enum field. Everything works fine until the form is submitted. It fails with a weird validation error -> "error.invalid"</p>
  
  <p>here's my code</p>
  
  <p>Enum class</p>
  
  <pre><code>package model;
  ...
  public enum UserType {
  
      UserType_Admin("Administrator"), UserType_Monitor("Monitor"), UserType_Audit("Audit");
      private String desc;
  
      private UserType(String desc) {
          this.desc = desc;
      }
  
      @Override
      public String toString() {
          return Messages.get(desc);
      }
  
      public String getLabel() {
          return toString();
      }
  
      public String getKey() {
          return super.toString();
      }
  
      public static Map&lt;String, String&gt; options() {
          LinkedHashMap&lt;String, String&gt; options = new LinkedHashMap&lt;String, String&gt;();
          for (UserType ut : UserType.values()) {
              Integer o = ut.ordinal();
              options.put(o.toString(), ut.desc);
          }
          return options;
      }
  }
  </code></pre>
  
  <p>My Entity</p>
  
  <pre><code>@Entity
  public class User extends Model {
  ...
      @Id
      public Long                      userID;
      public UserType                  user_type;
  }
  </code></pre>
  
  <p>Scala template</p>
  
  <pre><code>@form(routes.Users.save(userID)) {
     @select(
        userForm("user_type"),
        options(model.UserType.options),
        '_label -&gt; Messages("UserType"), '_default -&gt; Messages("choose_user_type"),
        '_showConstraints -&gt; true
      )
  }
  </code></pre>
  
  <p>on the controller the Save method:</p>
  
  <pre><code> public static Result save(Long userID) {
          Form&lt;User&gt; userForm = form(User.class).bindFromRequest();
          if (userForm.hasErrors()) {   &lt;- here it says that has errors
            return badRequest(useredit.render(new Session(session()), userID,
           userForm, new User()));
          }
    ...
  }
  </code></pre>
  
  <p>if I inspect the userForm variable, I get:</p>
  
  <blockquote>
    <p>Form(of=class model.User, data={user_type=0}, value=None,
    errors={user_type=[ValidationError(user_type,error.invalid,[])]})</p>
  </blockquote>
  
  <p>The field user_type has the correct value,  0 if I choose the first item, 1 for the second, etc.</p>
  
  <p><a href="https://www.dropbox.com/s/yy51olpiarkox7m/enum.png" rel="nofollow">Screenshot</a></p>
  
  <p>Anyone has a clue or a workaround for this? Maybe disable validation for this field? Tks guys</p>