0

In a Play (now 2.6) project, both annotation based validation (for example, @Constraints.Required) as well as validation via the Validatable (plus @Validate) are used. This worked fine until now, but as of play 2.6 both are now executed simultaneously per default.

This leads to the unfortunate effect, that the validate method (from Validatable) can now no longer be sure that all the other validations have already finished successfully, so we must add various null-checks, etc. in validate on fields that are already marked not-null per annotation.

Is there a way in Play 2.6 to get the behavior, that validate() is only called after all annotation based validation rules have finished successfully?

Florian Schaetz
  • 10,454
  • 5
  • 32
  • 58

1 Answers1

1

From https://www.playframework.com/documentation/2.6.x/Migration26#form-changes:

Be aware: The “old” validate method was invoked only after all other constraints were successful before. By default class-level constraints however are called simultaneously with any other constraint annotations - no matter if they passed or failed. To (also) define an order between the constraints you can now use constraint groups.

This is how that looks:

import javax.validation.GroupSequence;
import javax.validation.groups.Default;

@GroupSequence({ Default.class, SignUpCheck.class, LoginCheck.class })
public interface OrderedChecks { }

See https://www.playframework.com/documentation/2.6.x/JavaForms#advanced-validation for details.

cbley
  • 4,538
  • 1
  • 17
  • 32