kotlin data class + bean validation jsr 303

You need to use Annotation use-site targets since the default for a property declared in the constructor is to target the annotation on the constructor parameter instead of the getter (which will be seen by JavaBeans compliant hosts) when there are multiple options available. Also using a data class might be inappropriate here (see note … Read more

Spring MVC – @Valid on list of beans in REST service

@Valid is a JSR-303 annotation and JSR-303 applies to validation on JavaBeans. A java.util.List is not a JavaBean (according to the official description of a JavaBean), hence it cannot be validated directly using a JSR-303 compliant validator. This is supported by two observations. Section 3.1.3 of the JSR-303 Specification says that: In addition to supporting … Read more

Annotations from javax.validation.constraints not working

For JSR-303 bean validation to work in Spring, you need several things: MVC namespace configuration for annotations: <mvc:annotation-driven /> The JSR-303 spec JAR: validation-api-1.0.0.GA.jar (looks like you already have that) An implementation of the spec, such as Hibernate Validation, which appears to be the most commonly used example: hibernate-validator-4.1.0.Final.jar In the bean to be validated, … Read more

Hibernate Validation of Collections of Primitives

Neither JSR-303 nor Hibernate Validator has any ready-made constraint that can validate each elements of Collection. One possible solution to address this issue is to create a custom @ValidCollection constraint and corresponding validator implementation ValidCollectionValidator. To validate each element of collection we need an instance of Validator inside ValidCollectionValidator; and to get such instance we … Read more

Bean Validation @NotNull, @NotBlank and @NotEmpty does not work in JSF+Tomcat

Introduction Since you didn’t give any feedback on my comment with the question what container you’re using, I peeked around in your question history to learn what containers you’re all using. As far I found only Tomcat. So I’ll for this answer assume that you’re indeed using Tomcat as I initially guessed while posting the … Read more

How to perform JSF validation in actionListener or action method?

Introduction You can do it, but JSF ajax/action/listener methods are semantically the wrong place to do validation. You actually don’t want to get that far in JSF lifecycle if you’ve wrong input values in the form. You want the JSF lifecycle to stop after JSF validations phase. You want to use a JSR303 Bean Validation … Read more

How can I validate two or more fields in combination?

For multiple properties validation, you should use class-level constraints. From Bean Validation Sneak Peek part II: custom constraints: Class-level constraints Some of you have expressed concerns about the ability to apply a constraint spanning multiple properties, or to express constraint which depend on several properties. The classical example is address validation. Addresses have intricate rules: … Read more