Updated my proposed fix to mimic the setNestedProperty() method. if (bean instanceof Map) { // check to see if the class has a standard property PropertyDescriptor descriptor = getPropertyDescriptor(bean, next); if (descriptor == null) { // no - get the value bean = ((Map) bean).get(next); } else { // yes - use that instead bean = getMappedProperty(bean, next); } } else if (indexOfMAPPED_DELIM >= 0) {
Douglas Ross Developer, HTML UI Framework Kronos E-mail: [EMAIL PROTECTED] Voice: (978) 947-4305 Fax: (978) 256-2474 www.kronos.com Smaller, Faster, Sharper, Easier(tm) -----Original Message----- From: Ross, Douglas [mailto:[EMAIL PROTECTED] Sent: Thursday, October 07, 2004 4:42 PM To: Tag Libraries Users List Subject: PropertyUtils.getNestedProperty() and java.util.Map handling suggestion/question .... Problem: An application class that implements java.util.Map has special get/set methods. I would like the special methods to be invoked when action form is being populated from the request and when the html taglib accesses the data from this class. But because this class implements Map, PropertyUtils shortcuts to the Map.get() method, thus causing my application to fail. Example: In this example, item is my class which implements Map. <html:text property="item.firstName" /> PropertyUtils.getNestedProperty() calls item.get("firstName"). Now I want to use my special method: <html:text property="item.specialGetMethod(firstName)" /> PropertyUtils shortcuts to Map.get() method and calls item.get("specialGetMethod(firstName)"). The key "specialGetMethod(firstName)" does not exist. What I want obviously is PropertyUtils to defer to the getMappedProperty() which would correctly call item.getSpecialGetMethod("firstName"). Proposal: Change the getNestedProperty to test the name parameter to see if it is a mapped method + MAPPED_DELIM + value + MAPPED_DELIM2. If it is then skip the shortcut. Here is some sample code which works in my environment: public static Object PropertyUtils::getNestedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { . . . String next = name.substring(0, indexOfNESTED_DELIM); indexOfINDEXED_DELIM = next.indexOf(INDEXED_DELIM); indexOfMAPPED_DELIM = next.indexOf(MAPPED_DELIM); indexOfMAPPED_DELIM2 = next.lastIndexOf(MAPPED_DELIM2); // test: method(value); ignore: (value) boolean useMappedProperty = (indexOfMAPPED_DELIM > 0) && (indexOfMAPPED_DELIM2 == (name.length() - 1)); if (bean instanceof Map && !useMappedProperty) { bean = ((Map) bean).get(next); } else if (indexOfMAPPED_DELIM >= 0) { bean = getMappedProperty(bean, next); } else if (indexOfINDEXED_DELIM >= 0) { bean = getIndexedProperty(bean, next); } else { bean = getSimpleProperty(bean, next); } . . . } Questions: What is the rationale behind the current design? I understand the Map shortcut, but why does it ignore the fact that the property may be a method name *and* value? Has this issue been addressed in a newer version? Any suggestions? Environment: Struts 1.1, JRun 4.0 PropertyUtils class: /home/cvspublic/jakarta-commons/beanutils/src/java/org/apache/commons/be anutils/PropertyUtils.java,v 1.38 2003/01/15 21:59:39 rdonkin Exp $ $Revision: 1.38 $ $Date: 2003/01/15 21:59:39 $ Thanks in advance for any help, suggestions. Doug --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]