bean-validation

Spring MVC Date format validation with JSR303

帅比萌擦擦* 提交于 2019-11-30 21:22:53
问题 I'm using Spring MVC with JSR303 to do my input validation. A form I've created has a couple of date fields that are bound to Date objects within the object backing the form. I'm using JSR303 to do the validation for the Date using @Future . I'm also using @DateTimeFormat(pattern="dd/MM/yyyy") , (I know it's not validation). How do I validate the date format of the String on the form? If I leave the other required fields blank ( @NotEmpty ) and enter a non-valid date in the form 'dd/MM/yy' it

Hibernate Validator and Jackson: Using the @JsonProperty value as the ConstraintViolation PropertyPath?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 20:50:59
Say I have a simple POJO like below annotated with Jackson 2.1 and Hibernate Validator 4.3.1 annotations: final public class Person { @JsonProperty("nm") @NotNull final public String name; public Person(String name) { this.name = name; } } And I send JSON like such to a web service: {"name": null} Hibernate when it reports the ConstraintViolation uses the class member identifier "name" instead of the JsonProperty annotation value. Does anyone know if it is possible to make the Hibernate Validator look at the annotation of the class and use that value instead? No, that's not possible. Hibernate

JSF 2.0: h:inputText inside composite component fails with non-String objects when validation is set

落爺英雄遲暮 提交于 2019-11-30 19:59:52
问题 In a backing bean: @Min(3) Integer foo; If I have form like: <h:form> <h:commandButton value="Submit" /> <h:inputText value="#{bean.foo}" /> </h:form> This works ok. However, if I do something like <cc:interface> <cc:attribute name="text" /> <cc:editableValueHolder name="text" targets="field" /> <cc:interface> <cc:implementation> <h:inputText id="field" value="#{cc.attrs.text}" /> </cc:implementation> and call this inside form instead of directly h:inputText as in: <!-- <h:inputText value="#

How to avoid cross dependency between layers because of @Constraint validatedBy?

微笑、不失礼 提交于 2019-11-30 18:50:23
In our project we have Service and DAO layers in separate Maven modules. Service module depends on DAO module and works with it's entities. The problem is that we can't put custom jsr 303 constraint which uses some services from service layer in DAO entity because that would create the back reference from DAO layer to service layer, because the validator class needs to be referenced in validatedBy attribute of custom @Constraint. Is there a way (using standard jsr 303 api) to specify validator class of some custom constraint at runtime (or solve our problem in any other way)? The built in

error: No validator could be found for type: java.time.LocalDate

十年热恋 提交于 2019-11-30 18:07:53
I'm working on a project that uses bean validation (Hibernate Validator 5.1.3.Final). My bean has a attribute with the @Past annotation. @Past(message = "A data deve estar no passado.") private LocalDate dataAbertura; But, when the validation occurs I get the following exception: 21:46:12,424 ERROR [io.undertow.request] (default task-35) UT005023: Exception handling request to /financeiro/clientes/pessoafisica: javax.servlet.ServletException: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.time.LocalDate. at br.com.caelum.vraptor.VRaptor.doFilter

JSR303 Composite Annotation

♀尐吖头ヾ 提交于 2019-11-30 17:53:39
问题 I've created a composite annotation that consists of @Digits and @Min @Digits(integer=12, fraction=0) @Min(value=0) @ReportAsSingleViolation @Documented @Retention(RetentionPolicy.RUNTIME) @Target( { FIELD, METHOD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) @Constraint(validatedBy={}) public @interface PositiveInt { String message() default "{positive.int.msg}"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; } my problem is, I want to reuse this annotation

error: No validator could be found for type: java.time.LocalDate

假装没事ソ 提交于 2019-11-30 16:50:17
问题 I'm working on a project that uses bean validation (Hibernate Validator 5.1.3.Final). My bean has a attribute with the @Past annotation. @Past(message = "A data deve estar no passado.") private LocalDate dataAbertura; But, when the validation occurs I get the following exception: 21:46:12,424 ERROR [io.undertow.request] (default task-35) UT005023: Exception handling request to /financeiro/clientes/pessoafisica: javax.servlet.ServletException: javax.validation.UnexpectedTypeException: HV000030

spring-data-jpa bean validation in junit tests

烈酒焚心 提交于 2019-11-30 15:06:00
问题 In my recent work I've used spring-data-jpa to take advantage of provided repositories. When it came to integration tests I am unable to configure (I assume) spring context for testing and as a outcome bean validation doesn't work in my tests. I am aware that I can inject validator, and unit test my annotations but it's not the case. I am writing integration tests and would like to test repositories with DB backed. I have prepared simple project to show all necessary project files. When I run

Using both JSR-303 and Traditional Bean Validation?

二次信任 提交于 2019-11-30 13:58:34
问题 Is it possible to use both JSR-303 bean validation and traditional validation (a single validator class for the type) in Spring? If so, what configuration is required to set this up? I have tried the instructions on the reference. @InitBinder protected void initBinder(WebDataBinder binder) { binder.setValidator(new DualEntryValidator()); } @RequestMapping(value="/dualEntry.htm", method = RequestMethod.POST) public ModelAndView handlePost(@Valid DualEntryForm form, BindingResult result) {

spring-data-jpa bean validation in junit tests

谁说我不能喝 提交于 2019-11-30 13:27:52
In my recent work I've used spring-data-jpa to take advantage of provided repositories. When it came to integration tests I am unable to configure (I assume) spring context for testing and as a outcome bean validation doesn't work in my tests. I am aware that I can inject validator, and unit test my annotations but it's not the case. I am writing integration tests and would like to test repositories with DB backed. I have prepared simple project to show all necessary project files. When I run tests, 2 are failing and I have no idea why, hibernate validator is present on class path. Failed