[ http://mc4j.org/jira/browse/STS-425?page=comments#action_10972 ] John Newman commented on STS-425: ---------------------------------
Why not use Introspector or better yet stripes' own property expression stuff for that? I looked at this class a bit a while back, it is over 1000 lines and a real beast. The bind() method in particular is huge! I am scanning through it now trying to get some ideas for a better design - how about some physical separation between the routines for binding and validation (even conversion)? Maybe a DefaultActionBeanPropertyValidator could reduce some of the load and make this class easier to understand and subclass. ? I'll take a closer look in the next week > @Validate annotation on boolean property isXyz() fails > ------------------------------------------------------ > > Key: STS-425 > URL: http://mc4j.org/jira/browse/STS-425 > Project: Stripes > Issue Type: Bug > Components: Validation > Affects Versions: Release 1.5, Release 1.4.3 > Reporter: Frederic Daoud > Assigned To: Ben Gunter > Priority: Minor > Fix For: Release 1.5 > > > @Validate annotations work on fields, getters and setters. > For a boolean property xyz, the JavaBean convention is to name the getter > "isXyz". > Doing so makes the annotation fail, because Stripes assumes that the method > prefix is of length 3 (get/set). In the example above, the property name ends > up being "yz". > The core of the problem is in the "getPropertyName" method of the > DefaultActionBeanPropertyBinder class: > net.sourceforge.stripes.controller.DefaultActionBeanPropertyBinder > 563: protected String getPropertyName(String methodName) { > 564: return methodName.substring(3,4).toLowerCase() + > methodName.substring(4); > 565: } > This assumes that the property name is the method name with the first 3 > characters removed (get/set), which causes problems when the method name is > "isXyz". > Used in the "processClassAnnotations" method of the same class: > (lines 173-192): > Validate validation = method.getAnnotation(Validate.class); > if (validation != null) { > String fieldName = getPropertyName(method.getName()); // * > -- here -- * > fieldValidations.put(fieldName, validation); > } > ValidateNestedProperties nested = > method.getAnnotation(ValidateNestedProperties.class); > if (nested != null) { > String fieldName = getPropertyName(method.getName()); // * > -- here -- * > Validate[] validations = nested.value(); > for (Validate nestedValidate : validations) { > if ( "".equals(nestedValidate.field()) ) { > log.warn("Nested validation used without field name: > ", validation); > } > else { > fieldValidations.put(fieldName + "." + > nestedValidate.field(), > nestedValidate); > } > } > } > Easy workaround by annotating setter, field, or naming method getXyz() > instead of isXyz(); nevertheless, pointing out this bug which could cause > hard-to-find bugs to the unsuspecting developer. > Thanks, > Freddy > -- > Frederic Daoud -- 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 ------------------------------------------------------------------------- SF.Net email is sponsored by: Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Stripes-development mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/stripes-development
