You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jb...@apache.org on 2006/04/03 12:24:05 UTC

svn commit: r390992 - in /cocoon: branches/BRANCH_2_1_X/status.xml trunk/blocks-tobeconverted/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java

Author: jbq
Date: Mon Apr  3 03:24:02 2006
New Revision: 390992

URL: http://svn.apache.org/viewcvs?rev=390992&view=rev
Log:
Fix COCOON-1808 patched by Rob Berens

Modified:
    cocoon/branches/BRANCH_2_1_X/status.xml
    cocoon/trunk/blocks-tobeconverted/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=390992&r1=390991&r2=390992&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Mon Apr  3 03:24:02 2006
@@ -181,6 +181,9 @@
   <release version="@version@" date="@date@">
 -->
   <release version="2.1.9" date="TBD">
+    <action dev="JBQ" type="add" fixes-bug="COCOON-1808" due-to="Rob Berens" due-to-email="rberens@osirion.nl">
+      CForms: Added method StaticSelectionList.addItem(Object value, String label)
+    </action>
     <action dev="CZ" type="add">
       CForms: add dynamic id to Form object. This allows to use the same form model several times on
               the same page, for example if the form is used in a portal.

Modified: cocoon/trunk/blocks-tobeconverted/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks-tobeconverted/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java?rev=390992&r1=390991&r2=390992&view=diff
==============================================================================
--- cocoon/trunk/blocks-tobeconverted/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java (original)
+++ cocoon/trunk/blocks-tobeconverted/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java Mon Apr  3 03:24:02 2006
@@ -84,15 +84,43 @@
         this.items.add(new SelectionListItem(value, label));
     }
 
+    /**
+     * Adds a new item to this selection list.
+     * @param value a value of the correct type (i.e. the type with which this selectionlist is associated)
+     * @param label a String label, can be null
+     */
+    public void addItem(Object value, String label) {
+        this.items.add(new SelectionListItem(value, label));
+    }
+
+    /**
+     * Adds a new item to this selection list, where the label is set to the toString()
+     * result of the value.
+     * @param value a value of the correct type (i.e. the type with which this selectionlist is associated)
+     */
+    public void addItem(Object value) {
+        this.items.add(new SelectionListItem(value));
+    }
+
     public final class SelectionListItem {
         private final Object value;
-        private final XMLizable label;
+        private final Object label;
 
         public SelectionListItem(Object value, XMLizable label) {
             this.value = value;
             this.label = label;
         }
 
+        public SelectionListItem(Object value, String label) {
+            this.value = value;
+            this.label = label;
+        }
+
+        public SelectionListItem(Object value) {
+            this.value = value;
+            this.label = null;
+        }
+
         public Object getValue() {
             return value;
         }
@@ -111,10 +139,13 @@
             attrs.addCDATAAttribute("value", stringValue);
             contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, attrs);
             contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES);
-            if (this.label != null) {
-                this.label.toSAX(contentHandler);
-            } else {
+            if (this.label == null) {
                 contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length());
+            } else if (this.label instanceof XMLizable) {
+                ((XMLizable) this.label).toSAX(contentHandler);
+            } else {
+                String stringLabel = (String) this.label;
+                contentHandler.characters(stringLabel.toCharArray(), 0, stringLabel.length());
             }
             contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL);
             contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL);