hibernate-validator

Make custom hibernate validation annotation for email existence

蓝咒 提交于 2020-01-04 05:35:41
问题 i was wondering if it's possible to make custom hibernate validation annotation that will check in the database if the email exist or not (call dao method and return true if the email exist) so i can do something like: @NotBlank(message = "email is required") @Email(message = "{invalid.email}") @EmailExist(message = "{email.exist}") @Column(name = "email", length = 155, nullable = false) private String email; please advise with a sample if possible, thanks in advance. 回答1: Yes it should be

spring mvc process object before @valid is applied

拟墨画扇 提交于 2020-01-04 02:54:56
问题 I have a spring mvc controller like the following @RequestMapping(value="/new", method=RequestMethod.POST) public String createBooking(@Valid Booking booking, BindingResult bindingResult, Model model, Principal principal) { if(bindingResult.hasErrors()) { return "booking/edit"; } //Store Booking in db... ... The problem is the Booking object i get from the POST is constructed by Spring, but one of the properties required by the validator cannot be populated, as the property is not present in

Howto validate Collections in Maps

孤者浪人 提交于 2020-01-03 06:53:08
问题 I have a problem with the @Valid annotation of JSR-303. The annotation works fine for normal lists or and sets, but I am trying to validate Maps which contain Lists, i.e. @Valid HashMap<String, ArrayList<Object1>> map; In this case, instances of Object1 class are not validated. Is there a convenient way to do this recursively, without iterating over every object and validating it manually? 回答1: The specification does not specify the validation behavior when the map values are themselves lists

Message parameters not resolved in localized Spring Boot validation messages

霸气de小男生 提交于 2020-01-01 19:42:14
问题 I am building a project using Spring Boot 2.1.8 , I have spring-boot-starter-web in my POM and I can see Maven pulling hibernate-validator 6.0.17 onto the classpath. I have my messages in the resource folder and they appear to be looked up correctly so that when I change the locale Spring loads the message from the correct file. The relevant method in my @RestController takes a @Valid and @RequestBody annotated DTO. It triggers the ResponseEntityExceptionHandler#handleMethodArgumentNotValid()

Message parameters not resolved in localized Spring Boot validation messages

孤人 提交于 2020-01-01 19:42:04
问题 I am building a project using Spring Boot 2.1.8 , I have spring-boot-starter-web in my POM and I can see Maven pulling hibernate-validator 6.0.17 onto the classpath. I have my messages in the resource folder and they appear to be looked up correctly so that when I change the locale Spring loads the message from the correct file. The relevant method in my @RestController takes a @Valid and @RequestBody annotated DTO. It triggers the ResponseEntityExceptionHandler#handleMethodArgumentNotValid()

Overwriting default Hibernate Validator messages

扶醉桌前 提交于 2019-12-30 06:22:08
问题 I want to overwrite the default Hibernate Validator messages in a server faces web app, so I read this part of the documentation: https://docs.jboss.org/hibernate/validator/5.0/reference/en-US/html/chapter-message-interpolation.html#section-message-interpolation I created two files inside the src/ folder: ValidationMessages.properties and ValidationMessages_de_DE.properties . The file contents are: javax.validation.constraints.AssertFalse.message = must be false javax.validation.constraints

How to personality error message for hibernate validator enum?

不羁的心 提交于 2019-12-25 16:49:25
问题 I have a Spring MVC web application that uses JSR303 validation: import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.NotBlank; class User { @NotBlank(message = "user name is mandatory") String userName; public enum Color {RED, GREEN, YELLO} @NotNull(message = "color is mandatory) private Color color; } When my web controller validates User, it tells "color is mandatory" if this parameter has not been specified. This message is shown in the web form. However

Java validator for String

爷,独闯天下 提交于 2019-12-25 07:47:09
问题 How do I validate using Hibernate validator for elements appearing more than once in a JSON payload bound to a Java class annotated with validator annotations? Let's say I have the following: class Person { String name; int age; } I am binding JSON to Person. The JSON payload looks like the following: { "name":"someName", "age":30 } Let's say the payload has 2 "name" fields repeated as below. { "name":"someName", "name" : "otherName", "age":30 } Then I like to use the validator to validate

Creating custom unique constraints

牧云@^-^@ 提交于 2019-12-25 03:55:46
问题 I Defined my @FuSsA_UniqueKey constraint annotation: package com.fussa.employee.util; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import javax.validation.Constraint; import javax.validation.Payload; @Constraint(validatedBy = { UniqueIDValidator.class }) @Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface FuSsA_UniqueKey { String columnNames();

Jboss 7 migration - ValidationException: Unable to find provider: HibernateValidator

丶灬走出姿态 提交于 2019-12-25 03:28:39
问题 my work place is migrating from Jboss 6 to Jboss 7. We use v 5.1.3 Hibernate Validator, and when we tried to deploy our web application in the Jboss 7 server, and it threw an exception. 09:23:56,031 ERROR [org.jboss.as.controller.management-operation] (External Management Request Threads -- 4) WFLYCTL0013: Operation ("read-attribute") failed - address: ([ ("deployment" => "ROOT.war"), ("subsystem" => "jaxrs"), ("rest-resource" => "org.apache.cxf.rs.security.oauth.services.RequestTokenService"