You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2002/04/22 12:12:00 UTC
DO NOT REPLY [Bug 8364] New: -
java.util.List support for getIndexedProperty()
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8364>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8364
java.util.List support for getIndexedProperty()
Summary: java.util.List support for getIndexedProperty()
Product: Commons
Version: unspecified
Platform: All
OS/Version: Other
Status: NEW
Severity: Enhancement
Priority: Other
Component: Bean Utilities
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: volker.weber@atanion.com
While developping a application using struts we had to access elements of a
List interface. this dosn't works with current beanutils.
indexed access to 'Object[]' is implemented and with the same scheme it is
also posible to access elements of 'java.util.List'.
I have patched the class 'org.apache.commons.beanutils.PropertyUtils.java'
to meet our requirements.
I think this feature should added to beanutils.
diff of org.apache.commons.beanutils.PropertyUtils.java follows:
@@ -76,6 +76,7 @@
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.collections.FastHashMap;
+import java.util.List;
/**
@@ -409,19 +410,25 @@
}
}
- // Otherwise, the underlying property must be an array
+ // Otherwise, the underlying property must be an array or a List
Method readMethod = getReadMethod(descriptor);
if (readMethod == null)
throw new NoSuchMethodException("Property '" + name +
"' has no getter method");
- // Call the property getter and return the value
+ // Call the property getter and return the value
Object value = readMethod.invoke(bean, new Object[0]);
- if (!value.getClass().isArray())
- throw new IllegalArgumentException("Property '" + name +
- "' is not indexed");
- return (Array.get(value, index));
+ if (value.getClass().isArray())
+ return (Array.get(value, index));
+ else if (value instanceof List) {
+ return ((List)value).get(index);
+ }
+ else {
+ throw new IllegalArgumentException("Property '" + name +
+ "' is not indexed");
+
+ }
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>