bean-validation

Getting Spring 4 dependency injection working with RESTeasy 3 validator

末鹿安然 提交于 2019-12-23 04:46:00
问题 I have been running into a lot of trouble trying to get custom Bean Validation constraints to successfully leverage Spring's dependency injection. For example I might define a constraint: @Constraint(validatedBy = { CustomConstraintValidator.class }) @Documented @Target({ ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER }) @Retention(RetentionPolicy.RUNTIME) public @interface CustomConstraint { String message() default "custom.constraint.error"; Class<?>[]

How to Enable Spring Validation

寵の児 提交于 2019-12-23 03:45:07
问题 After putting hibernate-validator.jar and javax.validation-api.jar in my classpath the my old validation turned off and org.springframework.dao.DataIntegrityViolationException is replaced by org.hibernate.exception.ConstraintViolationException which wraps SQL exception that is coming from table constraints and this is causing a lot of issues. It automatically turned JSR-303 validation on so it doesn't validate anything anymore. I have to put this two jars to be able to upgrade Jersey to 2.4,

Is there a way to access the target bean from within a Bean Validation field-level ConstraintValidator?

纵饮孤独 提交于 2019-12-23 03:38:10
问题 Apart from using class-level validations, is there a way to access the parent bean of a field-level validation annotation from within its validator class? For example: public class CustomValidator implements ConstraintValidator<CustomValidation, String> { @Override public void initialize(final CustomValidation constraintAnnotation) { } @Override public boolean isValid(final String fieldValue, final ConstraintValidatorContext context) { // is there a way to access the parent object here? } }

JSR-303 errors not detected natively by using the @Valid annotation

放肆的年华 提交于 2019-12-22 13:52:49
问题 How come the @Valid annotation does not catch my JSR-303 annotations natively, but do catch them using the following method: WebConfig.java @Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); String[] strBaseNames = { "resources.messages.layout.LayoutResources", "resources.messages.layout.MenuResources", "resources.messages.global.GlobalResources" }; messageSource.setUseCodeAsDefaultMessage(true);

CXF in Karaf: how to configure bean validation on subresources (preferably using Blueprint)?

淺唱寂寞╮ 提交于 2019-12-22 11:33:54
问题 I'm using Dinamics Features of CXF in Karaf and faced with the issue that Bean Validation does not work for subresources. E.g. in the following code: @Path("services") public interface Service { @Path("{id}/orders") public Order getOrderForService(@PathParam("id") int serviceId); } @Path("orders") public interface Order { @POST Product getProduct(@NotNull @Valid Product product); } when Order is root resource, bean validation works fine, but when it is invoked as a subresource of Service,

Spring Data JPA validation is missing on update (merge)

我的未来我决定 提交于 2019-12-22 11:22:14
问题 I'm working on project with Spring boot 1.5.4.RELEASE with Spring Data JPA. Stuck on issue that Hibernate validator isn't executed when updating entity or at least in some cases it doesn't validate. For Person like below it is forbidden to have empty name and skills collection have to has min 1 element and max 5. Both of them are verified during call save on Spring Data repository. However for call save on already existing entity it will verify only constraints of name - and won't check

Using Spring's LocalValidatorFactoryBean with JSF

戏子无情 提交于 2019-12-22 09:23:40
问题 I am trying to get a bean injected into a custom ConstraintValidator . I have come across some things: CDI is supported in validation-api-1.1.0 (Beta available) Hibernate Validator 5 seems to implement validation-api-1.1.0 (Alpha available) Use Seam validation module Use Spring's LocalValidatorFactoryBean The last one seems most appropriate for my situation since we're already using Spring (3.1.3.Release). I have added the validator factory to the XML application context and annotations are

Using Spring's LocalValidatorFactoryBean with JSF

折月煮酒 提交于 2019-12-22 09:23:15
问题 I am trying to get a bean injected into a custom ConstraintValidator . I have come across some things: CDI is supported in validation-api-1.1.0 (Beta available) Hibernate Validator 5 seems to implement validation-api-1.1.0 (Alpha available) Use Seam validation module Use Spring's LocalValidatorFactoryBean The last one seems most appropriate for my situation since we're already using Spring (3.1.3.Release). I have added the validator factory to the XML application context and annotations are

@Valid (jsr 303) not working in Spring mvc 3.0

◇◆丶佛笑我妖孽 提交于 2019-12-21 23:53:41
问题 I'm trying to achieve the JSR 303 bean validation in Spring 3.0 by using a simple login use case. The problem is if I submit the form without any value the validation is not happening (i.e the BindingResult method hasErrors() always returning 'false' and printing I'm cool ! . Following is the code snippet: @Controller public class AnnotatedController { @RequestMapping(value = "login") public String validateLogin(@Valid LoginForm loginForm, BindingResult result, HttpServletRequest request) {

JSF 2 reusing the validation defined in the JPA entities?

若如初见. 提交于 2019-12-21 20:57:40
问题 Let's start with an example : In my JPA entity public class User { @Pattern("^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$", message="invalidEmailResourceBundleKey") private String email; @Min(5, message="minimumResourceBundleKey") private int age; ... } In my JSF Bean public class UserBean { private User user; // do i have to redefine it here, since it's already a part of the user ? @@Pattern("^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA