I have a custom object that represents my form like:
public class RegisterForm {
@NotNull(message = "Account name cannot be empty.")
@Size(min = 3, max = 50, message = "Account name must be between 3 and 50 characters long.")
private String accountName;
private boolean termsConditions;
}
My controller looks like:
public ModelAndView create(@Valid AccountForm accountForm, BindingResult bindingResult, HttpServletRequest request) {
}
So I added the boolean termsConditions that will be for a checkbox on the form.
What is the annotation I should use to ensure this value is true? i.e the checkbox is checked.
That would be javax.validation.constraints.AssertTrue
. From JavaDoc:
The annotated element must be true. Supported types are boolean and Boolean
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With