bean-validation

addPropertyNode - equivalent in version 1.0?

泪湿孤枕 提交于 2019-12-11 18:59:08
问题 Relatively simple probably. The Java 7 documentation for the ConstraintViolationBuilder interface specifies: addNode ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(String name) Deprecated. since 1.1 - replaced by addPropertyNode(String) and addBeanNode() Adds a node to the path the ConstraintViolation will be associated to. name describes a single property. In particular, dot (.) is not allowed. "Now" the documentation also includes the methods

How to stop DefaultListableBeanFactory from implicitly creating LocalValidatorFactoryBean instance

大城市里の小女人 提交于 2019-12-11 18:51:13
问题 I am using Spring 3.1 and have the following spring config where I explicitly create LocalValidatorFactoryBean using my own ValidationMessageSource . I have Hibernate Validator 4.1 in my class path. <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <value>ValidatorMsgID</value> </list> </property> </bean> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">

Cross Field Custom constraint annotation not working

南楼画角 提交于 2019-12-11 18:48:03
问题 i have a dropdown field named ContactTypeName which have the values like phone, email etc and an input field named Contact i want to validate the input field for valid email address if the dropdown value Email is selected... i have the following bean @FieldMatch.List({ @FieldMatch(first = "contactDetail", second = "contectTypeName", message = "Please Enter a valid email address") }) public class Contact { private int contactId = 0; @NotNull(message="Please Select a Contact Type") private

Springboot request object validation [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-11 17:51:00
问题 This question already has answers here : JSR-303 @Valid annotation not working for list of child objects (4 answers) Closed last year . I have a request object public class OrderRequest { private List<Details> detailsList; } public class Details{ Private String id; private List<Detail> detailList; } public class Detail{ @NotNull(message = "Please provide the inventory name") Private String inventoryName; Private String inventoryId; Private String inventoryLoc; } and i want to validate each

Display JSR-303 errors before form submission with Spring MVC

半腔热情 提交于 2019-12-11 16:43:29
问题 Is there an easy way in Spring MVC 3.x to display form error messages (obtained by JSR303 validation), before submiting the form ? Consider the example code at the end of this post. The end-user is supposed to edit forms in which the initial data is already invalid. Errors are properly displayed when the form is submitted (POST method), but not on initial form display (GET method). Is there an easy way to display the errors on initial form display (GET method) ? (Is there a way to re-use the

PowerMock error with hibernate validator (JSR - 303)

非 Y 不嫁゛ 提交于 2019-12-11 16:33:28
问题 We are using powermock for mocking static methods. Our code seems as follows public class ValidationLayer{ private GenericInputValidator v; public ValidationLayer(GenericValidator v){ this.v = v; } public boolean isValid(MyObject obj){ Logger.info(MyFinalClass.staticMethod()); return v.validate(); } } public class GenericInputValidator{ private MyOwnValidator validator; //setters & getters public boolean validate(Object toBeValidated){ validator.validate(toBeValidated); } } public class

Why does validation not work on objects of type DTO, but only on entities

混江龙づ霸主 提交于 2019-12-11 15:20:03
问题 I have an annotation set over objects of type dto , the same as over objects of type Entity . The annotation works on entities , but it does not work on objects of type dto . I work in SpringBoot . application.properties validate.packageid.size = "The field 'PACKAGEID' can contain only {max} symbols."; config file @Configuration public class ServiceConfig implements WebMvcConfigurer { @Bean public MessageSource messageSource() { ResourceBundleMessageSource source = new

Spring + App Engine + JSR303

两盒软妹~` 提交于 2019-12-11 12:50:37
问题 I am new to Spring and having issues with JSR303 Validation. The problem appears to be with the <mvc:annotation-driven/> tag in spring-servlet.xml. When I include this tag I get the following error on startup of the development server. SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is javax

Spring validation keeps validating the wrong argument

北城余情 提交于 2019-12-11 12:35:13
问题 I have a controller with a web method that looks like this: public Response registerDevice( @Valid final Device device, @RequestBody final Tokens tokens ) {...} And a validator that looks like this: public class DeviceValidator implements Validator { @Override public boolean supports(Class<?> clazz) { return Device.class.isAssignableFrom(clazz); } @Override public void validate(Object target, Errors errors) { // Do magic } } } I'm trying to get Spring to validate the Device argument which is

How can I use method-parameter level validation with JSF 2.2?

好久不见. 提交于 2019-12-11 11:50:35
问题 I have created a bean validator that I apply to my bean setter method. Instead of getting a JSF validation error, I get an exception raised. Is there a way to make this work, or I should go with a traditional JSF validator? //Bean Method public void setGuestPrimaryEmail(@ValidEmail String email){ guest.getEmails().get(0).setValue(email); } //Validator interface @Target({ElementType.FIELD,ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = EmailValidator.class