Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Critical
-
Resolution: Cannot Reproduce
-
Affects Version/s: Release 1.5.6
-
Fix Version/s: None
-
Component/s: Validation
-
Labels:None
Description
If you use the @ValidateNestedProperties annotation and some of your nested properties are required, you will get validation errors even the index property is null or not present in the request.
The Documentation at http://www.stripesframework.org/display/stripes/Indexed+Properties says:
.. Required field validations are only applied if at least one value with the same index was supplied. To understand this it is easier to think of indexed properties as a mechanism for creating multi-row forms. And this change means that rows in the form that are completely empty are ignored.
The nested validation below whould raise a validation error "name is required" even the indexed property books is not present in the request (null).
@ValidateNestedProperties({
@Validate(field = "name", required = true, maxlength = 100),
@Validate(field = "description", maxlength = 255)
})
private List<Book> books;
I fixed this problem and attached the modified classes.
@BenGunter: is the stripes project dead??
Attachments
Activity
| Field | Original Value | New Value |
|---|---|---|
| Attachment | DefaultValidationMetadataProvider.java [ 10540 ] |
| Fix Version/s | Release 1.5.7 [ 10150 ] |
| Resolution | Cannot Reproduce [ 5 ] | |
| Fix Version/s | Release 1.5.7 [ 10150 ] | |
| Assignee | Ben Gunter [ bengunter ] | |
| Status | Open [ 1 ] | Resolved [ 5 ] |
!! Please use the latest uploaded file DefaultValidationMetadataProvider.class !!
I added a check if the type of the field which holds the @ValidateNestedProperty annotation is an instanceof Iterable to mark this as an indexed property. This is a fix to the previous uploaded file which consider all properties holds the @ValidateNestedProperty are indexed properties.