bean-validation

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

邮差的信 提交于 2019-12-18 21:18:56
问题 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

How to manually trigger spring validation?

半城伤御伤魂 提交于 2019-12-18 18:47:35
问题 The annotated spring validation on fields of a POJO works when it is created from json request body. However, when I create the same object manually (using setters) and want to trigger validation, I'm not sure how to do that. Here is the Registration class, which has Builder inner class that can build the object. In the build method I would like to trigger spring validation. Please scroll to the bottom and check Builder.build() and Builder.valiate() methods to see current implementation. I'm

How to manually trigger spring validation?

走远了吗. 提交于 2019-12-18 18:47:04
问题 The annotated spring validation on fields of a POJO works when it is created from json request body. However, when I create the same object manually (using setters) and want to trigger validation, I'm not sure how to do that. Here is the Registration class, which has Builder inner class that can build the object. In the build method I would like to trigger spring validation. Please scroll to the bottom and check Builder.build() and Builder.valiate() methods to see current implementation. I'm

How to set check order for JSR303 bean validation

久未见 提交于 2019-12-18 13:31:23
问题 I use the JSR303 Bean Validation to check the form input. @NotBlank @Size(min = 4, max = 30) private String name; @NotBlank @Size(max = 100) @Email private String mail; when then name = '' and email = '',the @NotBlank, @Size at name, @NotBlank, @Size, @Email at mail will be checked. I want set the check order, when the previous order is invalid, the next is not checked, for example. @NotBlank(order = 1) @Size(min = 4, max = 30, order = 2) private String name; (above is not support by JSR303)

Making javax validation error message more specific

回眸只為那壹抹淺笑 提交于 2019-12-18 13:05:24
问题 Sorry if this question has been covered somewhere before. If it has please link me to it, I haven't been able to find a satisfactory answer as yet. I've been looking around trying to find a way to have the error messages provided by my javax validation more specific. The message I currently have for my @Min annotation is specified in the ValidationMessages.properties file: javax.validation.constraints.Min.message=The value of this variable must be less than {value}. and this prints out as

How do I use @Valid with Spring MVC's @RequestBody parameters?

感情迁移 提交于 2019-12-18 12:49:33
问题 I'm having an issue with using @Valid on a parameter to a handler method on my @Controller . My code looks like this: @RequestMapping(value=BIBBLE_BOBBLE_URI_PATTERN + "/widgets", method=RequestMethod.POST) @ResponseBody @ResponseStatus(HttpStatus.CREATED) public Widget saveNewWidget( @PathVariable final String username, @PathVariable final String bibbleBobbleName, @Valid @RequestBody final Widget widget, final BindingResult results, final HttpServletRequest request, final HttpServletResponse

Implementing custom validation logic for a spring boot endpoint using a combination of JSR-303 and Spring's Validator

孤人 提交于 2019-12-18 11:42:24
问题 I'm trying to implement some custom validation logic for a spring boot endpoint using a combination of JSR-303 Bean Validation API and Spring's Validator . Based on the Validator class diagram it appears to be possible to extend one of CustomValidatorBean , SpringValidatorAdapter or LocalValidatorFactoryBean to add some custom validation logic into an overridden method validate(Object target, Errors errors) . . However, if I create a validator extending any of these three classes and register

GWT JSR 303 client validation

时光怂恿深爱的人放手 提交于 2019-12-18 11:28:05
问题 I'm developing a GWT application with a Spring backend that uses JSR 303 validation. The application can go offline and use the browser HTML5/Gears database instead. What is the best way to implement the client validation? So far I have found gwt-validation framework (http://code.google.com/p/gwt-validation/) but it seems it is no longer active. Thanks! UPDATE: There is a new GWT official project to support JSR 303 Bean Validation (link here). IMO this is the way to go once the project is

Localization with bean validation in JSF

孤街浪徒 提交于 2019-12-18 10:56:21
问题 I made a MVC based website using JSF 2.0 and RichFaces 4. Every input text validation is been done using bean validation annotations. I am using Hibernate Validator as bean validation implementation. How can I display a localized message? If I use @NotNull(message="<h:outputText value=\"#{msg['Mymessage']}\" />") then it literally displays <h:outputText value="#{msg['Mymessage']}" /> as message. How is this caused and how can I solve it? 回答1: You should and can not put JSF tags in the message

Custom bean validation does not `@inject` CDI beans and does not interpolate message?

做~自己de王妃 提交于 2019-12-18 07:24:41
问题 I am using GF4 with bean validation. I am trying to @Inject a service bean in my custom validator but I get a null value. public class TestValidator implements ConstraintValidator<>{ @Inject Service myService; } Isn't this suppose to be working with JEE7? Also, I am trying to find built-in dynamic message interpolation (Without writing my own MessageInterpolator ). I did see some examples but they are not very clear. What I am looking for is to pass dynamic parameters from the