cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject svn commit: r618345 - /cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
Date Mon, 04 Feb 2008 17:47:59 GMT
Author: antonio
Date: Mon Feb  4 09:47:58 2008
New Revision: 618345

URL: http://svn.apache.org/viewvc?rev=618345&view=rev
Log:
Add API for dynamic suggestion list handling.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java?rev=618345&r1=618344&r2=618345&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
Mon Feb  4 09:47:58 2008
@@ -124,6 +124,10 @@
      * Overrides selection list defined in FieldDefinition, if any.
      */
     protected SelectionList selectionList;
+    /**
+     * Overrides sugestion list defined in FieldDefinition, if any.
+     */
+    protected SelectionList suggestionList;
 
     /**
      * Additional listeners to those defined as part of the widget definition (if any).
@@ -171,6 +175,7 @@
             setValue(value);
         }
         this.selectionList = this.definition.getSelectionList();
+        this.suggestionList = this.definition.getSuggestionList();
         this.required = this.definition.isRequired();
         super.initialize();
     }
@@ -245,7 +250,6 @@
                                             "'. Expected " + getDatatype().getTypeClass()
+ ", got " + newValue.getClass() + ").",
                                             getLocation());
         }
-
         // Is it a new value?
         boolean changed;
         if (this.valueState == VALUE_UNPARSED) {
@@ -590,6 +594,22 @@
     }
 
     /**
+     * Set this field's suggestion list.
+     * @param suggestionList The new suggestion list.
+     *
+     * @since 2.1.12
+     */
+    public void setSuggestionList(SelectionList suggestionList) {
+        if (suggestionList != null &&
+            suggestionList.getDatatype() != null &&
+            suggestionList.getDatatype() != getDatatype()) {
+            throw new RuntimeException("Tried to assign a SuggestionList that is not associated
with this widget's datatype.");
+        }
+        this.suggestionList = suggestionList;
+        getForm().addWidgetUpdate(this);
+    }
+
+    /**
      * Read this field's selection list from an external source.
      * All Cocoon-supported protocols can be used.
      * The format of the XML produced by the source should be the
@@ -622,8 +642,24 @@
         setSelectionList(getFieldDefinition().buildSelectionListFromModel(model, valuePath,
labelPath));
     }
 
+    /**
+     * Read this field's selection list from an external source.
+     * All Cocoon-supported protocols can be used.
+     * The format of the XML produced by the source should be the
+     * same as in case of inline specification of the selection list,
+     * thus the root element should be a <code>fd:selection-list</code>
+     * element.
+     * @param uri The URI of the source.
+     *
+     * @since 2.1.12
+     *
+     */
+    public void setSuggestionList(String uri) {
+        setSuggestionList(getFieldDefinition().buildSelectionList(uri));
+    }
+
     public SelectionList getSuggestionList() {
-        return getFieldDefinition().getSuggestionList();
+        return this.suggestionList;
     }
 
     public Datatype getDatatype() {



Mime
View raw message