struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andy Boyko" <abo...@fabgear.com>
Subject PATCH: taglib/form/OptionsTag - Map support
Date Wed, 15 Nov 2000 07:16:52 GMT
This patch allows the form taglib's OptionsTag to properly
support a java.util.Map as the collection it's iterating.

It assumes that the key of the map entries should be displayed
as the value of the <option> tag, and the value mapped to by
that key should be displayed as the label for the <option>.

Andy Boyko    aboyko@fabgear.com

RCS file:
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/form/Optio
nsTag.java,v
retrieving revision 1.2
diff -u -r1.2 OptionsTag.java
--- src/share/org/apache/struts/taglib/form/OptionsTag.java     2000/11/04
01:26:59  1.2
+++ src/share/org/apache/struts/taglib/form/OptionsTag.java     2000/11/15
07:08:49
@@ -183,10 +183,20 @@
        // Render the options tags for each element of the values collection
        StringBuffer sb = new StringBuffer();
        while (valuesIterator.hasNext()) {
-           String value = (String) valuesIterator.next();
-           String label = value;
-           if (labelsIterator.hasNext())
-               label = (String) labelsIterator.next();
+
+            Object next = valuesIterator.next();
+
+            String label, value;
+            if ( next instanceof Map.Entry ) {
+                Map.Entry entry = (Map.Entry) next;
+                value = (String) entry.getKey();
+                label = (String) entry.getValue();
+            } else {
+               value = (String) next;
+               label = value;
+               if (labelsIterator.hasNext())
+                   label = (String) labelsIterator.next();
+            }
            sb.append("<option value=\"");
            sb.append(value);
            sb.append("\"");


Mime
View raw message