EDIT: The form should not include the entire enumeration path, only the enumeration name. Therefore, in the ContactType class, the put method must be replaced with this:
put(value.name(),name);
I cannot associate an enumeration with a class. In the controller, I have something like this:
public Result saveUser() { Form<User> userForm = form(User.class).bindFromRequest(); if(userForm.hasErrors()) { return badRequest(createUser.render(userForm)); } User user=userForm.get(); user.save(); Logger.info(user.contacts.toString()); flash("success", "User " + userForm.get().identity + " has been created"); return GO_ADMIN; }
Which returns me all the time "error.invalid". The POST response is as follows:
identity=asas& status=1& contacts[0].name=fasddf& contacts[0].prename=afadfs& contacts[0] .email=ffdf@aa.com & contacts[0].contactType=models.constats.ContactType.MANAGER
To have more information, I provide here the classes "User" and "Contact"
User
public class User extends Model{ @Constraints.Required(message = "Field is required") public String identity; public Integer status; @Valid public List<Contact> contacts; }
Contact
public class Contact extends Generic{ @Constraints.Required(message = "Field is required") public String name; @Constraints.Required(message = "Field is required") public String prename; @Constraints.Required(message = "Field is required") @Constraints.Email public String email; public ContactType contactType; }
ContactType
public enum ContactType { ADMIN,SUPPORT,MANAGER,DEVELOPER,DESIGNER,NO_INFORMATION; } public static final Map<String,Object> types=new HashMap<String,Object>() {{ for (ContactType value : ContactType.values()) { String name=value.name().toLowerCase(); name=Character.toUpperCase(name.charAt(0)) + name.substring(1).replaceAll("_", " "); put(ContactType.class.getName() + "."+ value.name(),name); } }};