You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Arron <ar...@keyboardmonkey.com> on 2001/12/29 16:37:56 UTC
"Patch" for PropertyUtils...
Just had a quick look into allowing implementations of java.util.List
to act in place of arrays for the use of indexed properties.
Here's what's needed...
Replace lines 418 to 423 (inclusive. These line numbers are as of last
night's build) with the below code...
Code start --==>>
// Call the property getter and return the value
Object value = readMethod.invoke(bean, new Object[0]);
if (!value.getClass().isArray()) {
if (!(value instanceof java.util.List)) {
throw new IllegalArgumentException("Property '" + name
+ "' is not indexed");
} else {
return ((java.util.List)value).get(index);
}
}
return (Array.get(value, index));
<<==-- code finish.
It's just that at the end of the getIndexedProperty method, it gives up
on other versions of the indexed property and assumes it's been given an
array. Just an extra check to see if it's a list before giving up.
I've checked the bean spec, and it only states Arrays, but the class
already has support for Map implementations so why not Lists?...
The need for it came from Struts and people using the nesting extension,
as currently they have to return Object[] which is a pain when you're
using a perfectly good List implementation. It's a pain as the original
iterator can use any collection (for it cares not for the correct naming
of properties) but proper usage of properties means they're confined to
return primitive array types.
The above code is tested, and works a treat. I changed all returned
lists in my nesting example and it works perfect (nesting through three
lists).
If it sits well with all, and is added, that'd be fantastic.
Arron.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>