bean-validation

Empty validatedBy in @Constraint

十年热恋 提交于 2019-12-04 10:27:44
问题 I noticed that all built-in constraints have an empty value for the validatedBy parameter in @Constraint . i.e. @Constraint(validatedBy = {}) First, why are they allowed to have an empty value for validatedBy ? I thought you can leave it blank only for constraint composition that does not need addtional validation? Also, note that the Hibernate Validator can still find a validator implementation class for each built-in constraint, despite the validatedBy is empty, but if I leave the

Spring validator: having both annotation and validator implementation

冷暖自知 提交于 2019-12-04 07:03:14
Is it possible to have both a validator for a form and annotation constraints? For example to have in a form object this field: @NotEmpty private String date; but then validate the date's pattern in a validator. I know there is the pattern annotation but I just want to see if I can use both types of validating. Here is the link to a very good site where it's explained how you can combine the JSR-303 validator with the spring validator. I'll present next my solution that works. Hope it helps. My abstract Validator: import java.util.Map; import java.util.Set; import javax.validation

How to get the Invalid value in the error message while using custom validator in spring?

若如初见. 提交于 2019-12-04 07:02:41
问题 I having trouble in showing Invalid value in the error message I have messages.properties file as follows ProductId.exists.custom.validator.validation = A product already exists with product id ${validatedValue}. and following is my custom validtor interface @Target( { METHOD, FIELD, ANNOTATION_TYPE }) @Retention(RUNTIME) @Constraint(validatedBy = ProductIdValidator.class) @Documented public @interface ProductId { String message() default "{ProductId.exists.custom.validator.validation}";

Validation framework in C#?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 06:16:16
In the java world there is the bean validation framework JSR-303 which is a nicely well thought out strategy for performing data validation in both the presentation and persistence layers of an application. It covers a lot of things, including validation of whole graph models, validation domain grouping, i18n, etc. I have failed to find any data model validation frameworks in C#. Are there anything similar to JSR-303 in C#? There is the Enterprise Library Validation block. http://msdn.microsoft.com/en-us/library/ff648831.aspx It may not do some of the specific items you are asking about (i18n)

How to inject spring bean into Validator(hibernate)

可紊 提交于 2019-12-04 05:03:15
问题 spring doc I have read the following spring documentation: By default, the LocalValidatorFactoryBean configures a SpringConstraintValidatorFactory that uses Spring to create ConstraintValidator instances. This allows your custom ConstraintValidators to benefit from dependency injection like any other Spring bean. I have wrote custom validator: public class FieldMatchValidator implements ConstraintValidator<FieldMatch, Object>{ @Autowired MyBeanDao dao; ... } But in debug I see that dao is

javax.validation.NotBlank missing validator

老子叫甜甜 提交于 2019-12-04 04:29:35
I have requirement that in common api module(multi module project) I can't use any kind of hibernate's validation annotations, so I did use one from javax.validation which is acceptable. Problem starts when I want to validate my domain objects(I use vaadin) that contains NotBlank annotation. I get the following exception javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.NotBlank' validating type 'java.lang.String'. Check configuration for 'name' Validation is invoked by call Validation.buildDefaultValidatorFactory()

JSF: How validate fields and return error messages by bean validation?

天涯浪子 提交于 2019-12-04 04:11:13
I have a contact form and I have some fields that are validated by bean validation, how could I return bean validation error messages after submitting? For example: <h:form> <h:inputText id="name" value="#{contact.client.name}"></h:inputText>Name (Required) <h:inputText id="email" value="#{contact.client.email}"></h:inputText>E-Mail (Required) <h:inputText id="website" value="#{contact.client.website}"></h:inputText>Website (Optional) <h:inputText id="text" value="#{contact.client.text}"></h:inputText>Message (Required): <h:commandButton value="Send" action="#{contact.sendMessage}" > <f:ajax

Bean Validation with Extra Information

蹲街弑〆低调 提交于 2019-12-04 03:31:30
问题 I am trying to create a UniqueName annotation as a cutomize bean validation annotation for a create project api: @PostMapping("/users/{userId}/projects") public ResponseEntity createNewProject(@PathVariable("userId") String userId, @RequestBody @Valid ProjectParam projectParam) { User projectOwner = userRepository.ofId(userId).orElseThrow(ResourceNotFoundException::new); Project project = new Project( IdGenerator.nextId(), userId, projectParam.getName(), projectParam.getDescription() ); ... }

Validation for generated JAXB Classes (JSR 303 / Spring)

删除回忆录丶 提交于 2019-12-04 03:13:14
I Generated domain objects from schema (request & response) using JAXB (maven-jaxb2-plugin) I would like add validations (notnull /empty) for couple of attributes. I would like to have custom Bean Validation, the application is a REST service, i'm using Spring 3 and JSR 303 but i dont think i can use JSR 303 to validate the object as it is generated from the schema. can someone give me a nudge in the right direction on how to get this done. We've been using the Krasa JAXB plugin to generate JSR 303-annotated model beans from XSD files, and then telling Spring to automatically validate the

Cross field bean validation - why you no work

巧了我就是萌 提交于 2019-12-04 02:39:00
问题 I've got a little problem here with my application. I'd like to check if fields password and confirm password match together, so I tried to do it like in the first answer for this question: Cross field validation with Hibernate Validator (JSR 303) The problem is that it actually doesn't work and I HAVE NO IDEA WHY. Please, help me! This is my first post here, so please don't be too harsh for me. Here's my Annotation : /* * To change this template, choose Tools | Templates * and open the