bean-validation

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

久未见 提交于 2019-11-27 06:48:57
In a Spring MVC REST service (json), I have a controller method like this one : @RequestMapping(method = RequestMethod.POST, value = { "/doesntmatter" }) @ResponseBody public List<...> myMethod(@Valid @RequestBody List<MyBean> request, BindingResult bindingResult) { Where the MyBean class has bean validation annotations. The validations don't seem to take place in this case, although it works well for other controllers. I don't want to encapsulate the list in a dto this that would change the json input. Why is there no validations for a list of beans ? What are the alternatives ? @Valid is a

Bean validation doesn't work with mojarra 2.2.4

帅比萌擦擦* 提交于 2019-11-27 06:10:32
问题 I'm trying to use Hibernate Validator 5.0.1 and JSF2.2 but their integration seems to be broken since mojarra version 2.2.3. I've created small app to demonstrate the issue and get exception "javax.servlet.ServletException: Expression Error: Named Object: javax.faces.Bean not found." when running it on Tomcat 7.0.42. Does anyone else have this problem? webapp/pages/index.xhtml: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http:/

Customize spring validation error

人盡茶涼 提交于 2019-11-27 05:32:46
问题 I want customize the spring validation error for @NotNull @Length(max = 80) private String email; but I'm unable to do it. What are the step to follow? 回答1: The JSR 303 default message interpolation algorithm allows you to customize messages by supplying a resource bundle named ValidationMessages. Create a ValidationMessages.properties file in the classpath containing: javax.validation.constraints.NotNull.message=CUSTOM NOT NULL MESSAGE javax.validation.constraints.Size.message=CUSTOM SIZE

How can I disable javax.validation.api in JBoss 6.4

吃可爱长大的小学妹 提交于 2019-11-27 04:47:36
问题 Similar questions: How to use bean validation 1.1 in JBoss EAP 6.4.0? How to change bean-validation version on jboss EAP 6.3? Can you use bean validation 1.1 (JSR 349) in JBoss EAP 6.4.4? There seems to be some uncertainty if we can use Bean Validation 1.1 in JBoss 6.x. My current jboss-deployment-structure.xml: <?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"> <deployment> <dependencies> <!-- list of modules taken from https:/

Unique constraint with JPA and Bean Validation

和自甴很熟 提交于 2019-11-27 03:49:41
I'd like to have a @Unique constraint with Bean Validation, but that is not provided by the standard. If I would use JPA's @UniqueConstraint I wouldn't have a unique validation and error reporting mechanism. Is there a way to define @Unique as a Bean Validation constraint and combine it with JPA, such that JPA creates a column with an unique constraint and checks wheter a value is unique or not? Unless you acquire a lock on a whole table , it is basically not possible to check for unicity using a SQL query (any concurrent transaction could modify data after a manual check but before the commit

Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'

一笑奈何 提交于 2019-11-27 03:48:50
问题 I would like to store birthdate so I chose date at MySQL, when I create my entities based in my database, it turns out like this: import java.util.Date; // ..code @NotNull(message="fill you birthdate") @Temporal(TemporalType.DATE) private Date birthdate; But when I try to persist it gives me this error: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details. What am I doing

Bean Validation and error messages at .properties file

不羁岁月 提交于 2019-11-27 02:58:01
问题 i am working on a JSF Projekt with Glassfish. My validation works well but i dont become a custom error message. //Class = User, package = devteam @NotEmpty @Pattern(".+@.+\\.[a-z]+") private String emailAddress; My ValidationMessages.properties is in the WEB-INF folder with this content: devteam.User.emailAddress=Invalid e-mail address Thank you. 回答1: You are having two problems here. First, the location of the ValidationMessages.properties file. It has to be in the root of the classpath, so

Inject Service in ConstraintValidator [Bean Validator - JSR 303] Spring

偶尔善良 提交于 2019-11-27 02:45:10
问题 Good Afternoon, I am having problem to inject a service within a Bean Validator (JSR 303). I would be performing a validation, but I need to validate this record in my database; When I use my service it throws NullPointerException; Exception: Exception in thread "main" javax.validation.ValidationException: HV000028: Unexpected exception during isValid call. at org.hibernate.validator.internal.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:294) at org.hibernate.validator

Cross field validation with HibernateValidator displays no error messages

﹥>﹥吖頭↗ 提交于 2019-11-27 01:02:42
问题 I'm validating two fields, "password" and "confirmPassword" on the form for equality using HibernateValidator as specified in this answer. The following is the constraint descriptor (validator interface). package constraintdescriptor; import constraintvalidator.FieldMatchValidator; import javax.validation.Constraint; import javax.validation.Payload; import java.lang.annotation.Documented; import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import static java.lang.annotation

Is there an implementation of JSR-303 (bean validation) available?

霸气de小男生 提交于 2019-11-27 00:59:07
I know there are non-standard frameworks such as commons-validator, and hibernate validator. I wanted to know if someone knows an implementation of the official standard. skaffman Hibernate Validator is the reference implementation of JSR-303 bashflyng There are 2 compliant implementations now: Apache Bean Validation (formerly agimatec) Hibernate Validator You can access a benchmark and a quick description of both here: http://carinae.net/2010/06/benchmarking-hibernate-validator-and-apache-beanvalidation-the-two-jsr-303-implementations/ Implementations: agimatec-validation Hibernate Validator