[ http://mc4j.org/jira/browse/STS-425?page=all ]
Ben Gunter resolved STS-425.
----------------------------
Fix Version/s: Release 1.5
Resolution: Fixed
Assignee: Ben Gunter (was: Tim Fennell)
It now checks for get, set, and is prefixes.
> @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