Changeset 5233

Show
Ignore:
Timestamp:
08/21/08 10:18:44 (5 months ago)
Author:
marc.englund@…
Message:

Unified constructors + getter required, setter not; fixes #1998 and really-fixes #1076

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/com/itmill/toolkit/data/util/BeanItem.java

    r4543 r5233  
    99import java.beans.PropertyDescriptor; 
    1010import java.lang.reflect.Method; 
     11import java.util.Arrays; 
    1112import java.util.Collection; 
    1213import java.util.Iterator; 
     
    6364                final String name = pd[i].getName(); 
    6465 
    65                 if ((getMethod != null) && (setMethod != null)) { 
     66                if ((getMethod != null)) { 
    6667                    final Property p = new MethodProperty(type, bean, 
    6768                            getMethod, setMethod); 
     
    110111                        final Method setMethod = pd[i].getWriteMethod(); 
    111112                        final Class type = pd[i].getPropertyType(); 
    112  
    113                         final Property p = new MethodProperty(type, bean, 
    114                                 getMethod, setMethod); 
    115                         addItemProperty(name, p); 
     113                        if ((getMethod != null)) { 
     114                            final Property p = new MethodProperty(type, bean, 
     115                                    getMethod, setMethod); 
     116                            addItemProperty(name, p); 
     117                        } 
    116118                    } 
    117119                } 
     
    142144     */ 
    143145    public BeanItem(Object bean, String[] propertyIds) { 
    144         this.bean = bean; 
    145  
    146         // Try to introspect, if it fails, we just have an empty Item 
    147         try { 
    148             // Create bean information 
    149             final BeanInfo info = Introspector.getBeanInfo(bean.getClass()); 
    150             final PropertyDescriptor[] pd = info.getPropertyDescriptors(); 
    151  
    152             // Add all the bean properties as MethodProperties to this Item 
    153             for (int j = 0; j < propertyIds.length; j++) { 
    154                 final Object id = propertyIds[j]; 
    155                 for (int i = 0; i < pd.length; i++) { 
    156                     final String name = pd[i].getName(); 
    157                     if (name.equals(id)) { 
    158                         final Method getMethod = pd[i].getReadMethod(); 
    159                         final Method setMethod = pd[i].getWriteMethod(); 
    160                         final Class type = pd[i].getPropertyType(); 
    161  
    162                         final Property p = new MethodProperty(type, bean, 
    163                                 getMethod, setMethod); 
    164                         addItemProperty(name, p); 
    165                     } 
    166                 } 
    167             } 
    168  
    169         } catch (final java.beans.IntrospectionException ignored) { 
    170         } 
     146        this(bean, Arrays.asList(propertyIds)); 
    171147    } 
    172148