Passing Default group to form(...) in Play 2.6.x when using group constraints in forms

TIL if you pass custom groups to the form(...) method in Play 2.6.x, you also have to pass the group javax.validation.groups.Default explicitly—if you want any of its fields taken into account during the validation process of a form.

When only passing the group javax.validation.groups.Default you can omit it, because it is the default anyway.

Form<FooForm> form = formFactory().form(FooForm.class, Default.class).bindFromRequest();

is exactly the same as:

Form<FooForm> form = formFactory().form(FooForm.class).bindFromRequest();

However, if you pass any other group(s) you must also pass the Default group explicitly if you want any of its fields taken into account during the validation process.

So if you have a group constraint FooCheck, and you pass it to the form(...) method:

Form<FooForm> form = formFactory().form(FooForm.class, FooCheck.class).bindFromRequest();

Only the fields of FooCheck are validated. If you want the other fields also to be validated, you must pass Default explicitly:

Form<FooForm> form = formFactory().form(FooForm.class, Default.class, FooCheck.class).bindFromRequest();

See the migration guide here and the documentation of JavaForms here.


SHARE THIS ARTICLE