bean-validation

Java Bean Validation: GroupSequence with Class-Level Constraint

馋奶兔 提交于 2019-12-21 10:14:21
问题 I have a bean class with multiple (custom) inner constraints and one class-level constraint. I'd like to validate the inner constraints before the class-level constraint. The code looks like this: @GroupSequence({ Inner.class, NewSlotBean.class }) @TotalBeanValid(groups = NewSlotBean.class) public class NewSlotBean { @DayMonthYearString(groups = Inner.class) private String slotDay; @TimeString(groups = Inner.class) private String slotBegin; @LengthString(groups = Inner.class) private String

Spring MVC and JSR-303 hibernate conditional validation

我是研究僧i 提交于 2019-12-21 04:03:29
问题 I've a form I want to validate. It contains 2 Address variables. address1 has always to be validated, address2 has to be validated based on some conditions public class MyForm { String name; @Valid Address address1; Address address2; } public class Address { @NotEmpty private String street; } my controller automatically validates and binds my form obj @RequestMapping(...) public ModelAndView edit( @ModelAttribute("form") @Valid MyForm form, BindingResult bindingResult, ...) if(someCondition)

Spring Boot JSR-303/349 configuration

痴心易碎 提交于 2019-12-21 02:01:14
问题 In my Spring Boot 1.5.1 application I'm trying to configure support of JSR-303 / JSR-349 validation. I have added a following annotations @NotNull @Size(min = 1) to my method: @Service @Transactional public class DecisionDaoImpl extends BaseDao implements DecisionDao { @Override public Decision create(@NotNull @Size(min = 1) String name, String description, String url, String imageUrl, Decision parentDecision, Tenant tenant, User user) { ... } } I'm trying to invoke this method from my test,

JPA @Size annotation for BigDecimal

若如初见. 提交于 2019-12-20 18:29:11
问题 How do I use the @Size annotation for MySQL DECIMAL(x,y) columns? I'm using BigDecimal , but when I try to include the @Size max it doesn't work. Here is my code: @Size(max = 7,2) @Column(name = "weight") private BigDecimal weight; 回答1: You could use the Hibernate Validator directly, and annotate your field with @Digits like so: @Digits(integer=5, fraction=2) @Column(name = "weight") private BigDecimal weight; 回答2: See this answer @Column(nullable= false, precision=7, scale=2) // Creates the

Hibernate Validator - @Length - How to specify separate message for min and max?

旧城冷巷雨未停 提交于 2019-12-20 10:10:12
问题 I am using Hibernate validator for form validation in my web-app. I am using the @Length annotation for my String attribute as follows: @Length(min = 5, message = "The field must be at least 5 characters") private String myString; However, I have a need to display a different message if the String exceeds 50 characters. Is there a way to use the out-of-the-box @Length validator to do this? An example of what I would like to do (compiler will not let me) is as follows: @Length(min = 5, message

hibernate validator - different groups on create, update, delete

自闭症网瘾萝莉.ら 提交于 2019-12-20 01:05:32
问题 Using bean validation, particular hibernate validator implementation is it possible to define certain groups to automatically be used on certain crud operations like create or update? or are there some build in hibernate groups that are internally checked for those operations? 回答1: You're probably looking for "Hibernate event-based validation" under "ORM Integration". You can set properties to specify which groups to validate at different times by setting properties on the SessionFactory like

Why <f:validateBean /> won't work?

吃可爱长大的小学妹 提交于 2019-12-19 19:57:08
问题 I use JSF 2.0, hibernate-validator4.2.jar validation-api.jar tomcat and Eclipse. I put @Size(min=3, message="xxx") annotation in a @ManagedBean and <f:validateBean /> between <h:inputText value="#{user.name}"></h:inputText> When I try to run the project i get this error... exception javax.servlet.ServletException: Expression Error: Named Object: javax.faces.Bean not found. javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) root cause javax.faces.FacesException: Expression Error:

Why <f:validateBean /> won't work?

試著忘記壹切 提交于 2019-12-19 19:56:37
问题 I use JSF 2.0, hibernate-validator4.2.jar validation-api.jar tomcat and Eclipse. I put @Size(min=3, message="xxx") annotation in a @ManagedBean and <f:validateBean /> between <h:inputText value="#{user.name}"></h:inputText> When I try to run the project i get this error... exception javax.servlet.ServletException: Expression Error: Named Object: javax.faces.Bean not found. javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) root cause javax.faces.FacesException: Expression Error:

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

 ̄綄美尐妖づ 提交于 2019-12-19 11:05:54
问题 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

How to validate field level constraint before class level constraint?

人走茶凉 提交于 2019-12-19 04:15:15
问题 I have a class: @ColumnNameUnique(groups = CreateTableChecks.class) public class Table { @Valid @NotEmpty(groups = CreateTableChecks.class) private List<Measure> measures; } The class level constraint @ColumnNameUnique(groups = CreateTableChecks.class) always runs first, after that the field level constraint @NotEmpty(groups = CreateTableChecks.class) runs. Is there anyway to force the the field level constraint @NotEmpty(groups = CreateTableChecks.class) runs first? 回答1: You need to use