TheRock3t
TheRock3t

Reputation: 638

JSR 303 - Validate a field if it is not null

I have a form which is filled in, and some of the fields are options. I want to apply validations on the information that was filled in but the optional fields should be validated only if there was something filled in, so if theses are not null. Did any of you do something similar? Or do you have any suggestion?

Upvotes: 1

Views: 1187

Answers (1)

Gunnar
Gunnar

Reputation: 18990

Bean Validation constraints usually accept null as valid value (with the exception of @NotNull of course). Depending on your UI framework you might retrieve empty strings instead of null for fields without user input. If you're are working with JSF 2, you can set the context parameter javax.faces.VALIDATE_EMPTY_FIELDS to false to avoid a validation of empty fields.

Upvotes: 3

Related Questions