hibernate-validator

How to inject spring bean into Validator(hibernate)

ⅰ亾dé卋堺 提交于 2019-12-02 04:05:45
spring doc I have read the following spring documentation: By default, the LocalValidatorFactoryBean configures a SpringConstraintValidatorFactory that uses Spring to create ConstraintValidator instances. This allows your custom ConstraintValidators to benefit from dependency injection like any other Spring bean. I have wrote custom validator: public class FieldMatchValidator implements ConstraintValidator<FieldMatch, Object>{ @Autowired MyBeanDao dao; ... } But in debug I see that dao is null. Please, explain I didn't understand documentation or I wrong configured something? Use Spring

Hibernate validation error - @Size

依然范特西╮ 提交于 2019-12-02 03:48:02
问题 I have User entity and I try validate field password for length in my test. My User Class: public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @Column(name = "email", length = 100, nullable = false, unique = true) @NotEmpty @Email private String email; @Column(name = "password") @NotEmpty @Size(min = 5, max = 6) private String password; } There are 3 variants that I try. 1.When password's length < 5 @Test public void passwordIsShort() { User user = new

hibernate validator + jsf 2.0: ValidationMessages.properties in UTF-8

好久不见. 提交于 2019-12-02 02:22:19
问题 I have a problem with displaying custom ValidationMessages of Hibernate Validator in UTF-8. For common jsf messages I followed this advice: i18n with UTF-8 encoded properties files in JSF 2.0 appliaction - I created class Text and used it in faces-config.xml. This is working properly. But this approach is not working with ValidationMessages; special characters are not displayed in UTF-8. Could anyone give me some advice about this? Thank you very much 回答1: I have solved in the same way.

Hibernate validation error - @Size

微笑、不失礼 提交于 2019-12-02 01:15:46
I have User entity and I try validate field password for length in my test. My User Class: public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @Column(name = "email", length = 100, nullable = false, unique = true) @NotEmpty @Email private String email; @Column(name = "password") @NotEmpty @Size(min = 5, max = 6) private String password; } There are 3 variants that I try. 1.When password's length < 5 @Test public void passwordIsShort() { User user = new User(); user.setPassword("1"); Set<ConstraintViolation<User>> constraintViolations = validator

hibernate validator + jsf 2.0: ValidationMessages.properties in UTF-8

我只是一个虾纸丫 提交于 2019-12-01 22:45:45
I have a problem with displaying custom ValidationMessages of Hibernate Validator in UTF-8. For common jsf messages I followed this advice: i18n with UTF-8 encoded properties files in JSF 2.0 appliaction - I created class Text and used it in faces-config.xml. This is working properly. But this approach is not working with ValidationMessages; special characters are not displayed in UTF-8. Could anyone give me some advice about this? Thank you very much e-zinc I have solved in the same way. Hibernate validator has configuration file in META-INF/validation.xml Example for validation.xml

400 Bad request with Hibernate @Valid

好久不见. 提交于 2019-12-01 21:21:14
问题 I have a strange behaviour when I validate my form. As soon as I add the Hibernate @Valid annotation, Tomcat consided my request as "bad" if the posted data are not valid. If the data are valid, no worries. I use: Tomcat 7.0.52 Javax Validation api 1.1.0.Final Hibernate Validator 5.1.0.Final Spring 4.0.3.RELEASE At the moment, I do a really simple validation: public class RemoveCacheElementForm { @NotBlank(message = "Please select a cache name.") private String name; @NotBlank(message =

How to access a field which is described in annotation property

橙三吉。 提交于 2019-12-01 20:39:39
问题 Is it possible to access a field value, where field name is described in annotation which annotate another field in class. For example: @Entity public class User { @NotBlank private String password; @Match(field = "password") private String passwordConfirmation; } Annotation: @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = FieldMatchValidator.class) @Documented public @interface Match { String message() default "{}"; Class<?>[] groups() default {};

How to access a field which is described in annotation property

删除回忆录丶 提交于 2019-12-01 19:50:01
Is it possible to access a field value, where field name is described in annotation which annotate another field in class. For example: @Entity public class User { @NotBlank private String password; @Match(field = "password") private String passwordConfirmation; } Annotation: @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = FieldMatchValidator.class) @Documented public @interface Match { String message() default "{}"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; String field(); } Now, is it possible to access field

400 Bad request with Hibernate @Valid

旧时模样 提交于 2019-12-01 19:18:45
I have a strange behaviour when I validate my form. As soon as I add the Hibernate @Valid annotation, Tomcat consided my request as "bad" if the posted data are not valid. If the data are valid, no worries. I use: Tomcat 7.0.52 Javax Validation api 1.1.0.Final Hibernate Validator 5.1.0.Final Spring 4.0.3.RELEASE At the moment, I do a really simple validation: public class RemoveCacheElementForm { @NotBlank(message = "Please select a cache name.") private String name; @NotBlank(message = "Please select a cache entry key.") private String key; The Spring controller: /** * Handler to remove one

Hibernate validator for chars

别说谁变了你拦得住时间么 提交于 2019-12-01 17:35:30
问题 Is it possible to validate that a Character is either M or F or do I need to use a string with a regex? @Pattern(regexp = "^[MF]{1}$", message = "customer.sex.regex") private String sex; I would like to use private Character sex; 回答1: Your should this regular expression for accepting only M or F. @Pattern(regexp = "^[M|F]{1}$", message ="Must be M or F") In your second case of using as Character, you need to validate that this character is whether "M" or "F". Other can be set as sex. You