I can access (using BeanUtils.getProperty) the contents of an array
list[0].part, list[1].part, but I'd also like to access the size of the
array list.size.
Looking at v1.6 this does not work, as List.size() is not a 'real' java bean
property.
Is there a good way to do this with the bean utils?
Currently I have made a change to PropertyUtils to support this...
public static Object getSimpleProperty(Object bean, String name)
. . .
. . .
. . .
// Retrieve the property getter method for the specified property
PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
Method readMethod = null;
if (descriptor == null) {
// try other methods...
try {
readMethod = bean.getClass().getMethod(name, new Class[] {});
if (readMethod == null) {
throw new NoSuchMethodException("Unknown property '" + name
+ "'");
}
} catch(Exception e) {
throw new NoSuchMethodException("Unknown property '" + name +
"'");
}
} else
readMethod = getReadMethod(descriptor);
if (readMethod == null) {
throw new NoSuchMethodException("Property '" + name +
"' has no getter method");
}
// Call the property getter and return the value
Object value = readMethod.invoke(bean, new Object[0]);
return (value);
}
This seems to work fine, so my question is
a) is there a better way to do this?
b) is there any interest in having beanutils support this feature? I'd
prefer to keep to a core release of the commons jars.
Thanks
Paul Extance