Hi,
The only condition for this to work is that the objects in the array 
implements equals(...). The getObjectArrayProperty(...) function 
probably belongs in org.apache.commons.beanutils.BeanUtils.

joachim gjesdal

Index: 
jakarta-struts/src/share/org/apache/struts/taglib/html/MultiboxTag.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/html/MultiboxTag.java,v
retrieving revision 1.12
diff -u -r1.12 MultiboxTag.java
--- 
jakarta-struts/src/share/org/apache/struts/taglib/html/MultiboxTag.java   
 11 Dec 2001 17:54:28 -0000    1.12
+++ 
jakarta-struts/src/share/org/apache/struts/taglib/html/MultiboxTag.java   
 7 Mar 2002 17:03:44 -0000
@@ -73,6 +73,11 @@
 import org.apache.struts.util.MessageResources;
 import org.apache.struts.util.ResponseUtils;
 
+import java.util.*;
+import java.lang.reflect.Array;
+import org.apache.commons.beanutils.PropertyUtils;
+
+
 
 /**
  * Tag for input fields of type "checkbox".  This differs from CheckboxTag
@@ -130,7 +135,7 @@
      * The value which will mark this checkbox as "checked" if present
      * in the array returned by our property getter.
      */
-    protected String value = null;
+    protected Object value = null;
 
 
     // ------------------------------------------------------------- 
Properties
@@ -161,7 +166,7 @@
     /**
      * Return the server value.
      */
-    public String getValue() {
+    public Object getValue() {
 
     return (this.value);
 
@@ -173,7 +178,7 @@
      *
      * @param value The new server value
      */
-    public void setValue(String value) {
+    public void setValue(Object value) {
 
     this.value = value;
 
@@ -238,7 +243,7 @@
         results.append("\"");
     }
     results.append(" value=\"");
-        String value = this.value;
+        Object value = this.value;
         if (value == null)
             value = this.constant;
         if (value == null) {
@@ -248,17 +253,20 @@
                                      PageContext.REQUEST_SCOPE);
             throw e;
         }
-        results.append(ResponseUtils.filter(value));
+        if (value instanceof String){
+            value = ResponseUtils.filter((String)value);
+        }
+        results.append(value);
     results.append("\"");
     Object bean = pageContext.findAttribute(name);
-    String values[] = null;
+    Object values[] = null;
     if (bean == null)
         throw new JspException
         (messages.getMessage("getter.bean", name));
     try {
-        values = BeanUtils.getArrayProperty(bean, property);
+            values = getObjectArrayProperty(bean, property);
         if (values == null)
-        values = new String[0];
+        values = new Object[0];
         } catch (IllegalAccessException e) {
         throw new JspException
             (messages.getMessage("getter.access", property, name));
@@ -288,8 +296,43 @@
     return (EVAL_PAGE);
 
     }
-
-
+/**
+ *  Return the value of the specified array property of the specified
+ *  bean, as a String array.
+ *
+ *  This method probably belongs in commons.BeanUtils ??
+ */
+    
+    public static Object[] getObjectArrayProperty(Object bean, String name)
+        throws IllegalAccessException, InvocationTargetException,
+               NoSuchMethodException {
+        Object value = PropertyUtils.getProperty(bean, name);
+        if (value == null) {
+            return (null);
+        } else if (value instanceof Collection) {
+            ArrayList values = new ArrayList();
+            Iterator items = ((Collection) value).iterator();
+            while (items.hasNext()) {
+                    values.add(items.next());
+            }
+            return ((Object[]) values.toArray(new Object[values.size()]));
+        } else if (value.getClass().isArray()) {
+            ArrayList values = new ArrayList();
+            try {
+                int n = Array.getLength(value);
+                for (int i = 0; i < n; i++) {
+                    values.add(Array.get(value, i));
+                }
+            } catch (ArrayIndexOutOfBoundsException e) {
+                ;
+            }
+            return ((Object[]) values.toArray(new Object[values.size()]));
+        } else {
+            Object results[] = new Object[1];
+            results[0] = value;
+            return (results);
+        }
+    }
     /**
      * Release any acquired resources.
      */



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to