[ http://mc4j.org/jira/browse/STS-303?page=comments#action_10611 ] 
            
Iwao AVE! commented on STS-303:
-------------------------------

I needed to solve this problem for my project and made a patch.
It skips required validation when the property is 1) indexed and 2) not 
included in the request parameters.

===================================================================
--- 
src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java(revision
 486)
+++ 
src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java(working
 copy)
@@ -555,9 +555,23 @@
                     // Make the added check that if the form is a wizard, the 
required field is
                     // in the set of fields that were on the page
                     if (!wizard || fieldsOnPage.contains(propertyName)) {
-                        String[] values = 
bean.getContext().getRequest().getParameterValues(propertyName);
-                        log.debug("Checking required field: ", propertyName, 
", with values: ", values);
-                        checkSingleRequiredField(propertyName, propertyName, 
values, req, errors);
+                        // Check if the required field is indexed
+                        PropertyExpression propExpr = 
PropertyExpression.getExpression(propertyName);
+                        PropertyExpressionEvaluation propEval = new 
PropertyExpressionEvaluation(propExpr, bean);
+                        boolean isIndexed = false;
+                        for (NodeEvaluation nodeEval = propEval.getRootNode(); 
nodeEval != null && !isIndexed; 
+                            nodeEval = nodeEval.getNext()) 
+                        {
+                            NodeType  nodeType = nodeEval.getType();
+                            isIndexed = NodeType.ListEntry.equals(nodeType) 
+                                || NodeType.MapEntry.equals(nodeType) 
+                                || NodeType.ArrayEntry.equals(nodeType);
+                        }
+                        if (!isIndexed) {
+                            String[] values = 
bean.getContext().getRequest().getParameterValues(propertyName);
+                            log.debug("Checking required field: ", 
propertyName, ", with values: ", values);
+                            checkSingleRequiredField(propertyName, 
propertyName, values, req, errors);
+                        }
                     }
                 }
             }


There seemed to be several ways to detect if the property is indexed or not.
I used NodeType to do this but it might not be the most efficient way.
If someone knows a better way, please let me know.


> Nested validation errors reported when validating a null or zero length map.
> ----------------------------------------------------------------------------
>
>                 Key: STS-303
>                 URL: http://mc4j.org/jira/browse/STS-303
>             Project: Stripes
>          Issue Type: Bug
>          Components: Validation
>    Affects Versions: Release 1.4.1
>         Environment: Windows / Tomcat 5.5
>            Reporter: Simon Engledew
>         Assigned To: Tim Fennell
>
> I've been working on a javascript-enabled form that allows you to dynamically 
> add and remove 'rows' in a table, represented by TreeMaps of beans 
> stripes-side:
> public TreeMap<Long, ChannelDataBean> getChannels() { return this.channels; }
> public void setChannels(TreeMap<Long, ChannelDataBean> channels) { 
> this.channels = channels; }
> @ValidateNestedProperties
>     ({
>         @Validate(field="name", required=true, minlength=3, maxlength=50),
>         @Validate(field="incomingUsername", required=true, minlength=3, 
> maxlength=50),
>         @Validate(field="outgoingUsername", required=true, minlength=3, 
> maxlength=50),
>         @Validate(field="incomingPassword", required=true, minlength=3, 
> maxlength=50),
>         @Validate(field="outgoingPassword", required=true, minlength=3, 
> maxlength=50)
>     })
> private TreeMap<Long, ChannelDataBean> channels;
> and their appropriate inputs, generated by reflection, page side.
> It works great -- unless you try and submit a form with no elements at all. 
> In this case, Stripes reports validation errors for every single bean 
> property described in the corresponding nested @Validate annotation.
> Is there a work-around for this, aside from implementing a 
> ValidationErrorHandler (I kind of want the solution to be totally portable 
> and generic, which it is currently), or is this a bug.
> Cheers
> Si
> PS: I love stripes, it's seriously excellent. Cheers for the terrific 
> framework.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://mc4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to