bean-validation

springmvc jsr303 validator co-exist with spring WebDataBinder validator in one action

此生再无相见时 提交于 2019-12-05 10:41:50
Since springmvc 3.x now supports jsr303 and old spring style validator, i want to mix them in my sample apps. But there is only one method enabled for a specified controller, is that the limit of spring framework or JSR standard? Here is my sample code. User.java, stands for the domain model, uses JSR303 for validation. public class User{ @Size(max = 16, message = "user loginId max-length is 16") private String loginId; //omit getter and setter } UserValidator.java, implements the org.springframework.validation.Validator interface to support user validation. public class UserValidator

If I use two custom annotations in jsr 303 how to stop validation for second annotation if validation failed on first?

爷,独闯天下 提交于 2019-12-05 07:59:59
I have the next issue while working with jsr303: i have field annotated the next way: @NotEmpty(message = "Please specify your post code") @PostCode(message = "Your post code is incorrect") private String postCode; But I need to check @PostCode only if field passed the validation for @NotEmpty. How can I checking for tese two annotations? Thanks in advance You can use validation groups to execute validations group-wise. For details, see section 3.4. Group and group sequence in JSR-303 . In your sample you would do something like: @NotEmpty(message = "Please specify your post code") @PostCode

How to change the Validation Error behaviour for Dropwizard?

谁说胖子不能爱 提交于 2019-12-05 05:17:03
问题 In Dropwizard I use @Valid annotations for my resource methods: public class Address { @NotNull String street ... } @Path("/address") @Produces(MediaType.APPLICATION_JSON) public class AddressResource { @POST public MyResponse addAddress(@Valid Address address) { if (address == null) { throw new WebApplicationException("address was null"); } ... } } On application start I register a custom WebApplicationExceptionMapper which handles WebApplicationExceptions . Thus, for addresses with the

JSR 303 Bean Validation in Spring

こ雲淡風輕ζ 提交于 2019-12-05 03:25:02
问题 here is my formbean:- public class LoginFormBean { @NotEmpty private String userId; @NotEmpty private String password; public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getPassword() { return password; } public void setPassword(String pass) { this.password = pass; } } and in my message.properties file i write:- NotEmpty={0} must not empty. It shows me error message as: userId must not empty. and password must not empty.

How to solve NoSuchMethodError for javax.validation when deploying a spring boot application in weblogic server?

◇◆丶佛笑我妖孽 提交于 2019-12-05 02:23:24
问题 I am trying to deploy a simple spring boot application that will expose some rest api and I use hibernate entity manager to manipulate entity objects. When I try to deploy this application to Oracle Weblogic 12c, I get the following exception: <Jan 11, 2016 6:20:14 PM BDT> <Error> <Console> <BEA-240003> <Administration Console encountered the following error: weblogic.application.ModuleException: java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getParameterNameProvider(

Parametrizable JSR-303 validation values

落花浮王杯 提交于 2019-12-05 01:17:13
问题 I use JSR-303 bean validation and Spring 3 and I need to provide different values for the annotation depending on the use-case. For example, the value of min parameter in @Size(min=?) must be 1 for some validation and 5 for another case and I want to read this values from a properties file. I know the message parameter can be read from ValidationMessages.properties file if provided as a key but what about the other parameter? 回答1: As outlined by dpb you can use validation groups to specify

What is point of constraint validation @Null?

混江龙づ霸主 提交于 2019-12-04 23:19:31
I was checking list of available constraints in javax.validation package and I noticed that there is an annotation @Null which force the field to be null. I do not understand what is point of adding it to my field if I already know it should be null. For example look at this class: public class MyClass{ @NotNull private String myString1; @Null private String myString2; // getter setters... } @NotNull completely makes sense. I do not expect myString1 to be null. but @Null makes myString2 useless. What is point of having a field which should always be null. You may want to use @Null in

How to use SpringMVC @Valid to validate fields in POST and only not null fields in PUT

亡梦爱人 提交于 2019-12-04 23:01:39
问题 We are creating a RESTful API with SpringMVC and we have a /products end point where POST can be used to create a new product and PUT to update fields. We are also using javax.validation to validate fields. In POST works fine, but in PUT the user can pass only one field, and I can't use @Valid, so I will need to duplicate all validations made with annotation with java code for PUT. Anyone knows how to extend the @Valid annotation and creating something like @ValidPresents or something else

bean validation not working with kotlin (JSR 380)

牧云@^-^@ 提交于 2019-12-04 22:51:28
so first of all i could not think of a better title for this question so i'm open for changes. I am trying to validate a bean using the bean validation mechanism (JSR-380) with spring boot. So i got a controller like this: @Controller @RequestMapping("/users") class UserController { @PostMapping fun createUser(@Validated user: User, bindingResult: BindingResult): ModelAndView { return ModelAndView("someview", "user", user) } } with this being the User class written in kotlin: data class User( @field:NotEmpty var roles: MutableSet<@NotNull Role> = HashSet() ) and this being the test: @Test

f:convertNumber on Double: ClassCastException

廉价感情. 提交于 2019-12-04 20:39:05
In JSF 2.3, I have an h:inputText to edit a Double value, which has in addition Bean-Validation constraints. The h:inputText has a f:convertNumber . When submitting the form, this leads to a ClassCastException (see below). So, it seems, that f:convertNumber produces a Long which then, could not be converted to Double to validate the @DecimalMin constraint, right? In JSF 2.2 this worked as expected, the problem occured after upgrading to JSF 2.3. Does anybody has any ideas what could be the problem? I could reproduce this in WildFly 15.0.1 with the following minimal example with just one