hibernate-validator

How to localize Bean Validation messages

孤者浪人 提交于 2019-12-01 15:38:30
问题 I have a class and using annotation to validate the class properties. My web page (jsf2.2/primefaces/maven) is multilanguage (DE-utch, FR-rench, IT-alian). My problem is that the hibernate-validator has support for some languages(de, en, es, fr, hu, tr, pt_BR, mn_MN, zn_CN) but not Italian! (listed in the jar, org->hibernate->validator) So when i use the Italian version of my web page the validation messages are shown in english(default choice of hibernate). How i can override this, and

Cross field bean validation - why you no work

筅森魡賤 提交于 2019-12-01 14:41:47
I've got a little problem here with my application. I'd like to check if fields password and confirm password match together, so I tried to do it like in the first answer for this question: Cross field validation with Hibernate Validator (JSR 303) The problem is that it actually doesn't work and I HAVE NO IDEA WHY. Please, help me! This is my first post here, so please don't be too harsh for me. Here's my Annotation : /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package pl.lodz.p.zsk.ssbd2012.ssbd12.ValidationConstraints; import java.lang

How to validate a List<BigDecimal> with @DecimalMin and @DecimalMax?

心已入冬 提交于 2019-12-01 13:16:31
In my Spring project I have a POJO class with a property for a CMYK color. I want this property to be represented by a JSON array with exactly 4 floating-point numbers. Each number must be in the range between 0.0 and 1.0 . Currently I'm struggling with the validation of this property. I have researched already and found that the @DecimalMin and @DecimalMax annotations cannot be used on Float or float (see the answers to this question ). Therefore I already abandoned List<Float> and use List<BigDecimal> instead. Here is my stripped down POJO class: public class Settings { @NotNull @Size(min =

Hibernate Validator method or constructor validation

房东的猫 提交于 2019-12-01 12:00:58
How can I use Hibernate validator to validate the arguments inside the constructor or method? I want the validation to occur before the ValueObject creation so I can throw an exception and not create the object unless all parameters are valid. Basically I'm trying to use annotations instead of doing something like this if possible: public class ConditionalPerson { private String name; private String surname; private int age; public ConditionalPerson(String name, String surname, int age){ if (name == null || surname == null || age < 1) { throw new IllegalArgumentException(); } this.name = name;

JSR 303. Validate method parameter and throw exception

我的梦境 提交于 2019-12-01 11:58:57
问题 How can I use JSR-303 validate method parameters and throw exception if parameter is not valid? For example like this: public void createUser(@ValidOrThrowException User user) {...} ? For now, I check every method parameter in method body, like public void createUser(User user) { ConstraintViolations violations = Validator.validate(user); if (!violations.isEmpty()) { throw new IllegalArgumentException(createExceptionMessage(violations )); } ...//business logic } and I think it's ugly. P.S. As

Hibernate Validator method or constructor validation

≡放荡痞女 提交于 2019-12-01 10:52:17
问题 How can I use Hibernate validator to validate the arguments inside the constructor or method? I want the validation to occur before the ValueObject creation so I can throw an exception and not create the object unless all parameters are valid. Basically I'm trying to use annotations instead of doing something like this if possible: public class ConditionalPerson { private String name; private String surname; private int age; public ConditionalPerson(String name, String surname, int age){ if

Spring Boot: New Project - UnsatisfiedDependencyException: Error creating bean with name 'methodValidationPostProcessor'

大憨熊 提交于 2019-12-01 09:16:39
I just created a project using Spring Boot (1.5.2.BUILD-SNAPSHOT) on IntelliJ IDEA 2016.3.4 with Spring Initializr. When I try to run the project I got an exception due to ApplicationEventMulticaster and methodValidationPostProcessor. POM <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>mx.wedevelop</groupId> <artifactId>demo</artifactId> <version>0.0.1

Spring Boot: New Project - UnsatisfiedDependencyException: Error creating bean with name 'methodValidationPostProcessor'

送分小仙女□ 提交于 2019-12-01 07:07:38
问题 I just created a project using Spring Boot (1.5.2.BUILD-SNAPSHOT) on IntelliJ IDEA 2016.3.4 with Spring Initializr. When I try to run the project I got an exception due to ApplicationEventMulticaster and methodValidationPostProcessor. POM <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4

How to add custom error messages in Hibernate validator

…衆ロ難τιáo~ 提交于 2019-12-01 06:38:57
I have a simple class like this, import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Length; public class Form implements Serializable { @NotNull @Length(min = 2, max = 20) private String lastName; } I have messages.properties file in the classpath. It's then loaded via Spring bean as follows, <bean name="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="validationMessageSource"> <ref bean="resourceBundleLocator"/> </property> </bean> <bean name="resourceBundleLocator" class="org.springframework

Spring MVC Validation of Inherited Classes

孤街醉人 提交于 2019-12-01 04:09:04
I have a hard time believing I'm the only one who wants to do this, but I can't find any references to help me over my hurdle. Using Spring MVC and annotation-based validation (I'm using framework 4.0 and Java 1.7), consider a simple class hierarchy, as follows: abstract class Foo { @Size(max=10, message = "The name has to be 10 characters or less.") private String name; public String getName() { return this.name; } public void setName(String name) { this.name = name; } } class Bar extends Foo { } class Bang extends Foo { } If I put a name in an instance of either Bar or Bang that's greater