bean-validation

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

故事扮演 提交于 2019-12-06 07:47:26
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); messageSource.setDefaultEncoding("UTF-8"); messageSource.setBasenames(strBaseNames); return messageSource; }

java/beans validation - collection/map does not contain nulls

扶醉桌前 提交于 2019-12-06 05:51:07
There is the @NotNull annotation which validates that a certain object is not null. There is the @NotEmpty annotation which validates that a certain collection/map/string/... is not empty. Is there also an annotation which valides that a certain collection/map does not contain any nulls? I am unable to find it. It seems so basic, that I believe it must be in the JSR-303 spec. There is no such built-in constraints. You can easily write your custom constraints, eg @NoNullElements, which does what you want. Refer to the Refer to the documentation http://docs.jboss.org/hibernate/stable/validator

GroupSequence and ordered evaluation in JSR 303

好久不见. 提交于 2019-12-06 05:37:24
问题 In our application we have such a case: Constraints should be evaluated in particular order. (cheap to expensive) Constraints should not be evaluated after a violation per field. All fields should be validated. For first two, groupsequence is fitting very good. However for my 3rd requirement I could not find a way to solve. public class AccountBean { @CheepValidation @ExpensiveValidation @VeryExpensiveValidation private String name; @CheepValidation @ExpensiveValidation

Empty input value does not triggger @NotNull but it triggers @NotBlank

筅森魡賤 提交于 2019-12-06 05:29:56
i have this entity: import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.NotBlank; @Entity @XmlRootElement @Table public class Supplier extends AbstractEntity { @Column @NotNull private String name; @Column @NotBlank private String representative; ... } and this jsf form: <h:form> <p:commandButton value="save" action="#{supplierController.create}" ajax="false"/> <h:panelGrid columns="3" cellpadding="4"> <h:outputLabel value="#{bundle['Name']}" for="name"/> <p:inputText id="name" value="#{supplierController.value.name}"/> <p:message for="name"/> <h:outputLabel

JSR 303 Validation with Spring (MVC) on WebSphere

心已入冬 提交于 2019-12-06 05:25:28
I'm trying to do JSR 303 bean validation with a Spring MVC Controller in WAS 8.5.5.12 Full Profile. I'm validating just a single @RequestParam, not a full bean: @RequestMapping(method=RequestMethod.GET) public String initializeCheckIn( @Valid @Pattern(regexp = "^[\\p{Alnum}]*$") @RequestParam("officeid") String officeId, HttpSession session, Model model) { Before I added some Spring-specific configuration , no validation was occurring, but neither were any errors. Presumably, the validation wasn't being attempted at all. Now that I've added the necessary @Validated class annotation and bean

Bean Validation on method

筅森魡賤 提交于 2019-12-06 05:16:21
public class Register { @NotNull private String password; @NotNull private String passwordRepeat; @AssertTrue private boolean comparePasswords() { return password.equals(passwordRepeat); } private Set<ConstraintViolation<Register>> violations; public void doRegister(AjaxBehaviorEvent event) { Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); violations = validator.validate(this); if(violations.isEmpty()) { // This occurs } } } My validation will pass if both my passwords are not null, but they are different. Seems like the last constraint will not be taken into

Can't run java validation (JSR 303)

天大地大妈咪最大 提交于 2019-12-06 04:43:21
Recently ,I decide to use JSR 303 to validate bean In our project,But when i run JUNI test,It got error,The log is as below: java.lang.AbstractMethodError: org.hibernate.ejb.HibernatePersistence.getProviderUtil()Ljavax/persistence/spi/ProviderUtil; at javax.persistence.Persistence$1.isLoaded(Persistence.java:78) at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:61) at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:131) at org.hibernate.validator.engine.resolver

Spring validator: having both annotation and validator implementation

一笑奈何 提交于 2019-12-06 03:57:46
问题 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. 回答1: 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

Validate request headers with Spring validation framework

痴心易碎 提交于 2019-12-06 03:38:20
Is it possible to use the Spring validation framework with Spring MVC to validate the presence and value of an HTTP request header? To check the presence of a request header, you don't need the validation framework. Request header parameters are mandatory by default, and if a mandatory header is missing in a request, Spring MVC automatically responds with 400 Bad Request. So the following code automatically checks the presence of the header "Header-Name"... @PostMapping("/action") public ResponseEntity<String> doAction(@RequestHeader("Header-Name") String headerValue) { // ... } ... and if the

JSR303 - Apply all validation-groups defined in sequence

戏子无情 提交于 2019-12-06 03:02:15
I've got a bean I'd like to do conditional validation on. For this purpose, I've defined a DefaultGroupSequenceProvider<MyObject> which returns the list of groups to validate against. Now, when validating an object that violates the constraints in more than one group in the sequence, only the first group with failures return it's result. I'd like to get an error on all violations, not just the ones in the first group with failures. I'm thinking that this doesn't need a code-sample, but if I'm wrong, I'll be happy to provide one. I followed this http://kh-yiu.blogspot.com/2014/04/conditional