Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-170

java.util.List support for getIndexedProperty()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • None
    • None
    • None
    • Operating System: other
      Platform: All

    • 8364

    Description

      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"); + + }

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            volker.weber@atanion.com Volker Weber
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: