[
http://www.stripesframework.org/jira/browse/STS-868?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12740#comment-12740
]
Haggi commented on STS-868:
---------------------------
I think you misunderstood me ;)
The validation process will raise an error if the property is not present or
null, because of the implementation in validateRequiredFields() within the
DefaultActionBeanPropertyBinder.java class.
The assembling of index params at the top of the method is the cause of the
problem, because it collects only params as indexed params that are present in
the request.
{code}
// Assemble a set of names that we know have indexed parameters, so we won't
check
// for required-ness the regular way
Set<String> indexedParams = new HashSet<String>();
for (ParameterName name : parameters.keySet()) {
if (name.isIndexed()) {
indexedParams.add(name.getStrippedName());
}
}
{code}
So the better solution is extending the DefaultValidationMetadataProvider to
obtain the information out of the @NestedProperty annotated property, if it is
an instance of Iterable.
Please re-test it.
> Errors occured on null or not present indexed properties if required
> parameter is used within @ValidateNestedProperties
> -----------------------------------------------------------------------------------------------------------------------
>
> Key: STS-868
> URL: http://www.stripesframework.org/jira/browse/STS-868
> Project: Stripes
> Issue Type: Bug
> Components: Validation
> Affects Versions: Release 1.5.6
> Reporter: Haggi
> Assignee: Ben Gunter
> Priority: Critical
> Attachments: DefaultActionBeanPropertyBinder.java,
> DefaultValidationMetadataProvider.java,
> DefaultValidationMetadataProvider.java, ValidationMetadata.java
>
>
> 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:
> {quote}
> .. 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.
> {quote}
> The nested validation below whould raise a validation error "name is
> required" even the indexed property books is not present in the request
> (null).
> {code}
> @ValidateNestedProperties({
> @Validate(field = "name", required = true, maxlength = 100),
> @Validate(field = "description", maxlength = 255)
> })
> private List<Book> books;
> {code}
> I fixed this problem and attached the modified classes.
> @BenGunter: is the stripes project dead??
--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development