cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r155211 [1/2] - in cocoon/trunk: ./ src/blocks/forms/java/org/apache/cocoon/forms/binding/ src/blocks/forms/java/org/apache/cocoon/forms/event/ src/blocks/forms/java/org/apache/cocoon/forms/event/impl/ src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/ src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ src/blocks/forms/java/org/apache/cocoon/forms/generation/ src/blocks/forms/java/org/apache/cocoon/forms/util/ src/blocks/forms/java/org/apache/cocoon/forms/validation/impl/ src/blocks/forms/samples/ src/blocks/forms/samples/dreamteam/ src/blocks/forms/samples/forms/ src/blocks/forms/samples/resources/
Date Thu, 24 Feb 2005 17:06:13 GMT
Author: sylvain
Date: Thu Feb 24 09:05:51 2005
New Revision: 155211

URL: http://svn.apache.org/viewcvs?view=rev&rev=155211
Log:
Many changes to CForms - see status.xml

Removed:
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AddRowActionDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/DeleteRowsActionDefinition.java
Modified:
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBinding.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/JavaScriptJXPathBindingBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBinding.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/event/CreateEvent.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaScriptWidgetListener.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ClassDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FieldDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FieldDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Group.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MessagesDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/NewDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/OutputDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/SelectableWidget.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/StructDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/StructDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/SubmitDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/SubmitDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/UnionDefinition.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/UnionDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/UploadDefinitionBuilder.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionList.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/util/JavaScriptHelper.java
    cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/validation/impl/JavaScriptValidatorBuilder.java
    cocoon/trunk/src/blocks/forms/samples/dreamteam/sitemap.xmap
    cocoon/trunk/src/blocks/forms/samples/forms/datasource_chooser.xml
    cocoon/trunk/src/blocks/forms/samples/forms/datasource_chooser_binding.xml
    cocoon/trunk/src/blocks/forms/samples/forms/datasource_chooser_template.xml
    cocoon/trunk/src/blocks/forms/samples/forms/dynamicrepeater.xml
    cocoon/trunk/src/blocks/forms/samples/forms/form1.xml
    cocoon/trunk/src/blocks/forms/samples/forms/form2_model.xml
    cocoon/trunk/src/blocks/forms/samples/forms/form_model_gui_binding.xml
    cocoon/trunk/src/blocks/forms/samples/forms/form_model_gui_data.xml
    cocoon/trunk/src/blocks/forms/samples/forms/form_model_gui_model.xml
    cocoon/trunk/src/blocks/forms/samples/forms/form_model_gui_template.xml
    cocoon/trunk/src/blocks/forms/samples/forms/multipage_binding.xml
    cocoon/trunk/src/blocks/forms/samples/forms/multipage_model.xml
    cocoon/trunk/src/blocks/forms/samples/forms/multipage_template.xml
    cocoon/trunk/src/blocks/forms/samples/forms/tasktree.xml
    cocoon/trunk/src/blocks/forms/samples/forms/tasktree_binding.xml
    cocoon/trunk/src/blocks/forms/samples/forms/tasktree_template.xml
    cocoon/trunk/src/blocks/forms/samples/resources/forms-field-styling.xsl
    cocoon/trunk/src/blocks/forms/samples/sitemap.xmap
    cocoon/trunk/status.xml

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBinding.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBinding.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBinding.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBinding.java Thu Feb 24 09:05:51 2005
@@ -30,9 +30,7 @@
  *
  * @version $Id$
  */
-public class GroupJXPathBinding extends ComposedJXPathBindingBase {
-
-    private final String xpath;
+public class GroupJXPathBinding extends ContextJXPathBinding {
 
     private final String widgetId;
 
@@ -43,9 +41,8 @@
      * @param childBindings
      */
     public GroupJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String widgetId, String xpath, JXPathBindingBase[] childBindings) {
-        super(commonAtts, childBindings);
+        super(commonAtts, xpath, childBindings);
         this.widgetId = widgetId;
-        this.xpath = xpath;
     }
 
     /**
@@ -55,11 +52,7 @@
      */
     public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
         Group groupWidget = (Group)selectWidget(frmModel, this.widgetId);
-        JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
-        super.doLoad(groupWidget, subContext);
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("done loading " + toString());
-        }
+        super.doLoad(groupWidget, jxpc);
     }
 
     /**
@@ -69,14 +62,10 @@
      */
     public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
         Group groupWidget = (Group)selectWidget(frmModel, this.widgetId);
-        JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
-        super.doSave(groupWidget, subContext);
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("done saving " + toString());
-        }
+        super.doSave(groupWidget, jxpc);
     }
 
     public String toString() {
-        return "GroupJXPathBinding [widget=" + this.widgetId + ", xpath=" + this.xpath + "]";
+        return "GroupJXPathBinding [widget=" + this.widgetId + ", xpath=" + getXPath() + "]";
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/JavaScriptJXPathBindingBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/JavaScriptJXPathBindingBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/JavaScriptJXPathBindingBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/JavaScriptJXPathBindingBuilder.java Thu Feb 24 09:05:51 2005
@@ -90,7 +90,7 @@
                     throw new BindingException("Element \"load-form\" is missing (" +
                         DomHelper.getLocation(element) + ")");
                 }
-                loadScript = JavaScriptHelper.buildFunction(loadElem, JavaScriptJXPathBinding.LOAD_PARAMS);
+                loadScript = JavaScriptHelper.buildFunction(loadElem, "loadForm", JavaScriptJXPathBinding.LOAD_PARAMS);
             }
 
             // Build save script
@@ -101,7 +101,7 @@
                     throw new BindingException("Element \"save-form\" is missing (" +
                         DomHelper.getLocation(element) + ")");
                 }
-                saveScript = JavaScriptHelper.buildFunction(saveElem, JavaScriptJXPathBinding.SAVE_PARAMS);
+                saveScript = JavaScriptHelper.buildFunction(saveElem, "saveForm", JavaScriptJXPathBinding.SAVE_PARAMS);
             }
 
             // Build child bindings

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBinding.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBinding.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBinding.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBinding.java Thu Feb 24 09:05:51 2005
@@ -18,7 +18,6 @@
 import org.apache.cocoon.forms.formmodel.Struct;
 import org.apache.cocoon.forms.formmodel.Widget;
 import org.apache.commons.jxpath.JXPathContext;
-import org.apache.commons.jxpath.Pointer;
 
 /**
  * StructJXPathBinding provides an implementation of a {@link Binding}

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java Thu Feb 24 09:05:51 2005
@@ -16,6 +16,7 @@
 package org.apache.cocoon.forms.binding;
 
 import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.util.log.DeprecationLogger;
 import org.w3c.dom.Element;
 
 /**
@@ -37,6 +38,7 @@
 
     public JXPathBindingBase buildBinding(Element bindingElm, JXPathBindingManager.Assistant assistant)
             throws BindingException {
+        DeprecationLogger.log("'fb:struct' is deprecated and replaced by 'fb:group' at " + DomHelper.getLocation(bindingElm));
         try {
             String widgetId = DomHelper.getAttribute(bindingElm, "id");
             CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElm);

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/event/CreateEvent.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/event/CreateEvent.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/event/CreateEvent.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/event/CreateEvent.java Thu Feb 24 09:05:51 2005
@@ -18,7 +18,6 @@
 import org.apache.cocoon.forms.formmodel.Widget;
 
 /**
- * <b>Early prototype of a create event. Don't use it now as the plumbing is not yet ready! (SW)</b>
  * An event raised when a widget is created, once it has been fully set up. For
  * container widgets, this occurs after child widgets, if any, have been created.
  * 

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaScriptWidgetListener.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaScriptWidgetListener.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaScriptWidgetListener.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaScriptWidgetListener.java Thu Feb 24 09:05:51 2005
@@ -56,10 +56,12 @@
             
             HashMap values = new HashMap(2);
             values.put("event", event);
+            //FIXME(SW) it would be nice to have "this" be the widget, but I don't know how to define
+            //the "this" object for a script (this is easy for a function)
             
             Map objectModel = ContextHelper.getObjectModel(context);
 
-            // Add the biz data that was passed to showForm()
+            // Add the view data that was passed to showForm()
             Object viewData = FlowHelper.getContextObject(objectModel);
             if (viewData != null) {
                 values.put("viewData", viewData);

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js Thu Feb 24 09:05:51 2005
@@ -27,28 +27,31 @@
 /**
  * Create a form, given the URI of its definition file
  */
-function Form(uri) {
+function Form(formDefinition) {
     var formMgr = null;
     var resolver = null;
     var src = null;
     var xmlAdapter = null;
     try {
         formMgr = cocoon.getComponent(Packages.org.apache.cocoon.forms.FormManager.ROLE);
-        resolver = cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
-        src = resolver.resolveURI(uri);
-        this.form = formMgr.createForm(src);
-        this.binding = null;
-        this.eventHandler = null;
-        // FIXME : hack needed because FOM doesn't provide access to the context
-        this.avalonContext = formMgr.getAvalonContext();
-        // TODO : do we keep this ?
-        this.formWidget = new Widget(this.form);
-
+        if ((typeof formDefinition) == "string" || formDefinition instanceof String) {
+            resolver = cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
+            src = resolver.resolveURI(formDefinition);
+            this.form = formMgr.createForm(src);
+        } else {
+            this.form = formMgr.createForm(formDefinition)
+        }
     } finally {
         cocoon.releaseComponent(formMgr);
         if (src != null) resolver.release(src);
         cocoon.releaseComponent(resolver);
     }
+    this.binding = null;
+    this.eventHandler = null;
+    // FIXME : hack needed because FOM doesn't provide access to the context
+    this.avalonContext = formMgr.getAvalonContext();
+    // TODO : do we keep this ?
+    this.formWidget = new Widget(this.form);
 }
 
 Form.prototype.getModel = function() {
@@ -95,7 +98,7 @@
  * @parameter bizdata some business data for the view (like in cocoon.sendPageAndWait()).
  *            The "{FormsPipelineConfig.CFORMSKEY}" and "locale" properties are added to this object.
  */
-Form.prototype.showForm = function(uri, bizData) {
+Form.prototype.showForm = function(uri, bizData, fun, ttl) {
 
     if (bizData == undefined) bizData = new Object();
     bizData[Packages.org.apache.cocoon.forms.transformation.FormsPipelineConfig.CFORMSKEY] = this.form;
@@ -110,39 +113,27 @@
     var finished = false;
     this.isValid = false;
 
-    // FIXME: Remove check for removed syntax later.
-    if (this.validator != undefined) {
-        throw "Forms do not support custom javascript validators anymore. Declare your validators in the form model file.";
-    }
-
-    do {
-        var k = cocoon.sendPageAndWait(uri, bizData);
-        if (result == null) result = k;
-
+    var comingBack = false;
+    var bookmark = cocoon.createWebContinuation(ttl);
+    
+    if (comingBack) {
+        // We come back to the bookmark: process the form
         var formContext = new Packages.org.apache.cocoon.forms.FormContext(cocoon.request, this.locale);
-
-        // Prematurely add the bizData as in the object model so that event listeners can use it
-        // (the same is done by cocoon.sendPage())
-        // FIXME : hack needed because FOM doesn't provide access to the object model
-        var objectModel = org.apache.cocoon.components.ContextHelper.getObjectModel(this.avalonContext);
-        org.apache.cocoon.components.flow.FlowHelper.setContextObject(objectModel, bizData);
-
         finished = this.form.process(formContext);
         if (finished) {
             this.isValid = this.form.isValid();
+            var widget = this.form.getSubmitWidget();
+            // Can be null on "normal" submit
+            this.submitId = widget == null ? null : widget.getId();
+            return bookmark;
         }
-
-        // FIXME: Theoretically, we should clone the form widget (this.form) to ensure it keeps its
-        // value with the continuation. We don't do it since there should me not much pratical consequences
-        // except a sudden change of repeaters whose size changed from a continuation to another.
-
-    } while(!finished);
-
-    var widget = this.form.getSubmitWidget();
-    // Can be null on "normal" submit
-    this.submitId = widget == null ? null : widget.getId();
-
-    return result;
+    }
+    comingBack = true;
+    cocoon.sendPage(uri, bizData, bookmark);
+    if (fun && fun instanceof Function) {
+        fun();
+    }
+    FOM_Cocoon.suicide();
 }
 
 Form.prototype.createBinding = function(bindingURI) {

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java Thu Feb 24 09:05:51 2005
@@ -40,6 +40,8 @@
     }
 
     public void addWidgetDefinition(WidgetDefinition definition) throws Exception, DuplicateIdException {
+        //FIXME: cannot enforce this check here as more children are added in the resolve() phase
+        //checkMutable();
         definition.setParent(this);
         definitions.addWidgetDefinition(definition);
     }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java Thu Feb 24 09:05:51 2005
@@ -52,6 +52,8 @@
         while(it.hasNext()) {
           ((Widget)it.next()).initialize();
         }
+        
+        super.initialize();
     }
 
     public void addChild(Widget widget) {

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinition.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinition.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinition.java Thu Feb 24 09:05:51 2005
@@ -33,23 +33,32 @@
  */
 public abstract class AbstractDatatypeWidgetDefinition extends AbstractWidgetDefinition implements Serviceable {
     private Datatype datatype;
+    private Object initialValue;
     private SelectionList selectionList;
     private ValueChangedListener listener;
     private ServiceManager manager;
 
     public void service(ServiceManager manager) throws ServiceException {
+        checkMutable();
         this.manager = manager;
     }
 
     public Datatype getDatatype() {
         return datatype;
     }
+    
+    public Object getInitialValue() {
+        return this.initialValue;
+    }
 
-    public void setDatatype(Datatype datatype) {
+    public void setDatatype(Datatype datatype, Object initialValue) {
+        checkMutable();
         this.datatype = datatype;
+        this.initialValue = initialValue;
     }
 
     public void setSelectionList(SelectionList selectionList) {
+        checkMutable();
         if (selectionList != null && selectionList.getDatatype() != getDatatype())
             throw new RuntimeException("Tried to assign a SelectionList that is not associated with this widget's datatype.");
         this.selectionList = selectionList;
@@ -86,6 +95,7 @@
     }
     
     public void addValueChangedListener(ValueChangedListener listener) {
+        checkMutable();
         this.listener = WidgetEventMulticaster.add(this.listener, listener);
     }
     

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -15,11 +15,18 @@
  */
 package org.apache.cocoon.forms.formmodel;
 
+import java.util.Iterator;
+import java.util.Locale;
+
 import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.cocoon.forms.Constants;
+import org.apache.cocoon.forms.datatype.Datatype;
 import org.apache.cocoon.forms.datatype.SelectionList;
 import org.apache.cocoon.forms.datatype.SelectionListBuilder;
+import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
+import org.apache.cocoon.forms.event.ValueChangedListener;
 import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.i18n.I18nUtils;
 import org.w3c.dom.Element;
 
 /**
@@ -29,13 +36,47 @@
  */
 public abstract class AbstractDatatypeWidgetDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
     
-    /**
-     * @return true if a selectionlist has actually been build.
-     */
-    protected boolean buildSelectionList(Element widgetElement, AbstractDatatypeWidgetDefinition widget) throws Exception {
+    protected void setupDefinition(Element widgetElement, AbstractDatatypeWidgetDefinition definition) throws Exception {
+        super.setupDefinition(widgetElement, definition);
+        // parse "label", "hint", etc.
+        setDisplayData(widgetElement, definition);
+
+        // parse "on-value-changed"
+        Iterator iter = buildEventListeners(widgetElement, "on-value-changed", ValueChangedListener.class).iterator();
+        while (iter.hasNext()) {
+            definition.addValueChangedListener((ValueChangedListener)iter.next());
+        }
+        
+        //---- parse "datatype"
+        Element datatypeElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "datatype");
+        if (datatypeElement == null) {
+            throw new Exception("A nested datatype element is required for the widget " 
+                                + widgetElement.getTagName() + " at " + DomHelper.getLocation(widgetElement));
+        }
+
+        Datatype datatype = datatypeManager.createDatatype(datatypeElement, false);
+        
+        //---- parse "initial-value"
+        Object initialValue = null;
+        Element initialValueElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "initial-value", false);
+        if (initialValueElement != null) {
+            String localeValue = DomHelper.getAttribute(initialValueElement, "locale", null);
+            Locale locale = localeValue == null ? null : I18nUtils.parseLocale(localeValue);
+            String value = DomHelper.getElementText(initialValueElement);
+            ConversionResult result = datatype.convertFromString(value, locale);
+            if (!result.isSuccessful()) {
+                throw new Exception("Cannot parse initial value '" + value + "' at " +
+                        DomHelper.getLocation(initialValueElement));
+            }
+            initialValue = result.getResult();
+        }
+        
+        definition.setDatatype(datatype, initialValue);
+        
+        //---- parse "selection-list"
         // FIXME: pass the manager to the definition as a side effect. Should be removed
         // when definition are managed like components.
-        widget.service(this.serviceManager);
+        definition.service(this.serviceManager);
 
         Element selectionListElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "selection-list");
         if (selectionListElement != null) {
@@ -50,18 +91,14 @@
                 }
 
                 builder = (SelectionListBuilder)builderSelector.select(listType);
-                SelectionList list = builder.build(selectionListElement, widget.getDatatype());
-                widget.setSelectionList(list);
+                SelectionList list = builder.build(selectionListElement, definition.getDatatype());
+                definition.setSelectionList(list);
             } finally {
                 if (builder != null) {
                     builderSelector.release(builder);
                 }
                 this.serviceManager.release(builderSelector);
             }
-
-            return true;
-        } else {
-            return false;
         }
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java Thu Feb 24 09:05:51 2005
@@ -23,6 +23,7 @@
 import java.util.Map;
 
 import org.apache.cocoon.forms.Constants;
+import org.apache.cocoon.forms.event.CreateEvent;
 import org.apache.cocoon.forms.event.WidgetEvent;
 import org.apache.cocoon.forms.validation.WidgetValidator;
 import org.apache.cocoon.xml.AttributesImpl;
@@ -74,7 +75,7 @@
      * looking up case widgets for union widgets.
      */
     public void initialize() {
-        // Do nothing.
+        ((AbstractWidgetDefinition)getDefinition()).widgetCreated(this);
     }
 
     /**
@@ -96,7 +97,7 @@
      * @return the widgetDefinition from which this widget was instantiated. 
      *        (@link WidgetDefinition#createInstance()}
      */
-    protected abstract WidgetDefinition getDefinition();
+    public abstract WidgetDefinition getDefinition();
 
     /**
      * @return the location-information (file, line and column) where this widget was 
@@ -226,11 +227,11 @@
     }
 
     public Object getValue() {
-        return null;
+        throw new UnsupportedOperationException("Widget " + toString() + " has no value, at " + getLocation());
     }
 
     public void setValue(Object object) {
-        throw new RuntimeException("Cannot set the value of widget " + getRequestParameterName());
+        throw new UnsupportedOperationException("Widget " + toString() + " has no value, at " + getLocation());
     }
 
     public boolean isRequired() {
@@ -244,7 +245,11 @@
      * Concrete subclass widgets need to override when supporting event broadcasting.
      */
     public void broadcastEvent(WidgetEvent event) {
-        throw new UnsupportedOperationException("Widget " + this.getRequestParameterName() + " doesn't handle events.");
+        if (event instanceof CreateEvent) {
+            ((AbstractWidgetDefinition)getDefinition()).fireCreateEvent((CreateEvent)event);
+        } else {
+            throw new UnsupportedOperationException("Widget " + this.getRequestParameterName() + " doesn't handle events.");
+        }
     }
 
     /**
@@ -459,6 +464,6 @@
         if (last != -1) {
             className = className.substring(last+1);
         }
-        return className + "@" + getRequestParameterName();
+        return className + "-" + getRequestParameterName();
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java Thu Feb 24 09:05:51 2005
@@ -42,6 +42,8 @@
     //TODO consider final on these
     private String location = null;
     private String id;
+    /** the definition is mutable when being built */
+    private boolean mutable = true;
     /** The initial map of attributes (can be null) */
     private Map attributes;
     private Map displayData;
@@ -60,11 +62,29 @@
         }
         return this.formDefinition;
     }
+    
+    /**
+     * Locks this definition so that it becomes immutable.
+     */
+    public void makeImmutable() {
+        this.mutable = false;
+    }
+    
+    /**
+     * Check that this definition is mutable, i.e. is in setup phase. If not, throw an exception.
+     */
+    protected void checkMutable() {
+        if (!this.mutable) {
+            throw new IllegalStateException("Attempt to modify an immutable WidgetDefinition");
+        }
+    }
 
     /**
      * Sets the parent of this definition
      */
     public void setParent(WidgetDefinition definition) {
+        //FIXME(SW) calling checkMutable() here is not possible as NewDefinition.resolve() does some weird
+        //reorganization of the definition tree
         this.parent = definition;
     }
 
@@ -81,10 +101,12 @@
     }
 
     public void setState(WidgetState state) {
+        checkMutable();
         this.state = state;
     }
 
     protected void setLocation(String location) {
+        checkMutable();
         this.location = location;
     }
 
@@ -97,10 +119,12 @@
     }
 
     protected void setId(String id) {
+        checkMutable();
         this.id = id;
     }
 
     protected void setAttributes(Map attributes) {
+        checkMutable();
         this.attributes = attributes;   
     }
     
@@ -113,10 +137,21 @@
     }
 
     protected void addCreateListener(CreateListener listener) {
+        checkMutable();
         this.createListener = WidgetEventMulticaster.add(this.createListener, listener);
     }
+    
+    public void widgetCreated(Widget widget) {
+        if (this.createListener != null) {
+            widget.getForm().addWidgetEvent(new CreateEvent(widget));
+        }
+    }
 
     public void fireCreateEvent(CreateEvent event) {
+        // Check that this widget was created by the current definition
+        if (event.getSourceWidget().getDefinition() != this) {
+            throw new IllegalArgumentException("Widget was not created by this definition");
+        }
         if (this.createListener != null) {
             this.createListener.widgetCreated(event);
         }
@@ -134,10 +169,12 @@
      * @param displayData an association of {name, sax fragment}
      */
     public void setDisplayData(Map displayData) {
+        checkMutable();
         this.displayData = displayData;
     }
 
     public void addValidator(WidgetValidator validator) {
+        checkMutable();
         if (this.validators == null) {
             this.validators = new ArrayList();
         }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -63,8 +63,14 @@
         this.widgetValidatorBuilderSelector = (ServiceSelector) serviceManager.lookup(WidgetValidatorBuilder.ROLE + "Selector");
         this.widgetListenerBuilderSelector = (ServiceSelector) serviceManager.lookup(WidgetListenerBuilder.ROLE + "Selector");
     }
+    
+    protected void setupDefinition(Element widgetElement, AbstractWidgetDefinition definition) throws Exception {
+        setCommonProperties(widgetElement, definition);
+        setValidators(widgetElement, definition);
+        setCreateListeners(widgetElement, definition);
+    }
 
-    protected void setCommonProperties(Element widgetElement, AbstractWidgetDefinition widgetDefinition) throws Exception {
+    private void setCommonProperties(Element widgetElement, AbstractWidgetDefinition widgetDefinition) throws Exception {
         // location
         widgetDefinition.setLocation(DomHelper.getLocation(widgetElement));
 
@@ -164,7 +170,7 @@
         widgetDefinition.setDisplayData(displayData);
     }
 
-    protected void setValidators(Element widgetElement, AbstractWidgetDefinition widgetDefinition) throws Exception {
+    private void setValidators(Element widgetElement, AbstractWidgetDefinition widgetDefinition) throws Exception {
         Element validatorElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "validation");
         if (validatorElement != null) {
             NodeList list = validatorElement.getChildNodes();
@@ -187,7 +193,7 @@
         }
     }
 
-    protected void setCreateListeners(Element widgetElement, AbstractWidgetDefinition widgetDefinition) throws Exception {
+    private void setCreateListeners(Element widgetElement, AbstractWidgetDefinition widgetDefinition) throws Exception {
         Iterator iter = buildEventListeners(widgetElement, "on-create", CreateListener.class).iterator();
         while (iter.hasNext()) {
             widgetDefinition.addCreateListener((CreateListener)iter.next());

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java Thu Feb 24 09:05:51 2005
@@ -40,7 +40,7 @@
         this.definition = definition;
     }
 
-    protected WidgetDefinition getDefinition() {
+    public WidgetDefinition getDefinition() {
         return this.definition;
     }
 
@@ -125,8 +125,13 @@
     }
 
     public void broadcastEvent(WidgetEvent event) {
-        this.definition.fireActionEvent((ActionEvent)event);
-        fireActionEvent((ActionEvent)event);
+        if (event instanceof ActionEvent) {
+            this.definition.fireActionEvent((ActionEvent)event);
+            fireActionEvent((ActionEvent)event);
+        } else {
+            // Other kinds of events
+            super.broadcastEvent(event);
+        }
     }
 
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinition.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinition.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinition.java Thu Feb 24 09:05:51 2005
@@ -41,6 +41,7 @@
     }
 
     public void addActionListener(ActionListener listener) {
+        checkMutable();
         this.listener = WidgetEventMulticaster.add(this.listener, listener);
     }
     

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -19,6 +19,7 @@
 
 import org.apache.cocoon.forms.event.ActionListener;
 import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.util.log.DeprecationLogger;
 import org.w3c.dom.Element;
 
 /**
@@ -27,23 +28,36 @@
  * @version $Id$
  */
 public class ActionDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
+    
     public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
-        ActionDefinition actionDefinition = createDefinition();
-        setCommonProperties(widgetElement, actionDefinition);
-        setDisplayData(widgetElement, actionDefinition);
+        ActionDefinition definition = new ActionDefinition();
+        setupDefinition(widgetElement, definition);
+        definition.makeImmutable();
+        return definition;
+    }
+    
+    protected void setupDefinition(Element widgetElement, ActionDefinition definition) throws Exception {
+        super.setupDefinition(widgetElement, definition);
+
+        setDisplayData(widgetElement, definition);
 
-        String actionCommand = DomHelper.getAttribute(widgetElement, "action-command");
-        actionDefinition.setActionCommand(actionCommand);
+        // Get the "command" optional attribute
+        String actionCommand = DomHelper.getAttribute(widgetElement, "command", null);
+        
+        // If unspecified, check the deprecated "action-command" deprecated attribute
+        if (actionCommand == null) {
+            actionCommand = DomHelper.getAttribute(widgetElement, "action-command", null);
+            if (actionCommand != null) {
+                DeprecationLogger.log("The 'action-command' attribute is deprecated and replaced by 'command', at " +
+                    DomHelper.getLocation(widgetElement));
+            }
+        }
+        
+        definition.setActionCommand(actionCommand);
 
         Iterator iter = buildEventListeners(widgetElement, "on-action", ActionListener.class).iterator();
         while (iter.hasNext()) {
-            actionDefinition.addActionListener((ActionListener)iter.next());
+            definition.addActionListener((ActionListener)iter.next());
         }
-
-        return actionDefinition;
-    }
-    
-    protected ActionDefinition createDefinition() {
-        return new ActionDefinition();
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinition.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinition.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinition.java Thu Feb 24 09:05:51 2005
@@ -66,6 +66,7 @@
 
 
     public void addWidgetDefinition(WidgetDefinition widgetDefinition) throws DuplicateIdException {
+        checkMutable();
         container.addWidgetDefinition(widgetDefinition);
     }
 
@@ -74,6 +75,7 @@
     }
 
     protected void setCombineExpression(Expression expression) {
+        checkMutable();
         combineExpr = expression;
     }
 
@@ -82,6 +84,7 @@
     }
 
     protected void setSplitPattern(Pattern pattern, String regexp) {
+        checkMutable();
         this.splitPattern = pattern;
         this.splitRegexp = regexp;
     }
@@ -99,10 +102,12 @@
     }
 
     protected void setSplitFailMessage(XMLizable splitFailMessage) {
+        checkMutable();
         this.splitFailMessage = splitFailMessage;
     }
 
     protected void addSplitMapping(int group, String fieldId) {
+        checkMutable();
         splitMappings.add(new SplitMapping(group, fieldId));
     }
 
@@ -112,6 +117,8 @@
 
     public Widget createInstance() {
         AggregateField aggregateField = new AggregateField(this);
+        // Set the initial selection list, if any
+        aggregateField.setSelectionList(getSelectionList());
 
         Iterator fieldDefinitionIt = container.getWidgetDefinitions().iterator();
         while (fieldDefinitionIt.hasNext()) {

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -34,15 +34,23 @@
 public class AggregateFieldDefinitionBuilder extends FieldDefinitionBuilder {
 
     public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
-        AggregateFieldDefinition aggregateDefinition = new AggregateFieldDefinition();
-        buildWidgetDefinition(aggregateDefinition, widgetElement);
+        AggregateFieldDefinition definition = new AggregateFieldDefinition();
+        setupDefinition(widgetElement, definition);
+        definition.makeImmutable();
+        return definition;
+    }
+    
+    protected void setupDefinition(Element widgetElement, AggregateFieldDefinition definition) throws Exception {
+        
+        // parse the field definition
+        super.setupDefinition(widgetElement, definition);
 
         // make children fields
         Element widgetsElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "widgets", true);
         Element[] fieldElements = DomHelper.getChildElements(widgetsElement, Constants.DEFINITION_NS, "field");
         for (int i = 0; i < fieldElements.length; i++) {
             FieldDefinition fieldDefinition = (FieldDefinition)buildAnotherWidgetDefinition(fieldElements[i]);
-            aggregateDefinition.addWidgetDefinition(fieldDefinition);
+            definition.addWidgetDefinition(fieldDefinition);
         }
 
         // compile splitpattern
@@ -55,7 +63,7 @@
         } catch (MalformedPatternException e) {
             throw new Exception("Invalid regular expression at " + DomHelper.getLocation(splitElement) + ": " + e.getMessage());
         }
-        aggregateDefinition.setSplitPattern(pattern, patternString);
+        definition.setSplitPattern(pattern, patternString);
 
         // read split mappings
         Element[] mapElements = DomHelper.getChildElements(splitElement, Constants.DEFINITION_NS, "map");
@@ -64,7 +72,7 @@
             int group = DomHelper.getAttributeAsInteger(mapElements[i], "group");
             String field = DomHelper.getAttribute(mapElements[i], "field");
             // check that this field exists
-            if (!aggregateDefinition.hasWidget(field)) {
+            if (!definition.hasWidget(field)) {
                 throw new Exception("Unkwon widget id \"" + field + "\", at " +
                                     DomHelper.getLocation(mapElements[i]));
             }
@@ -73,14 +81,14 @@
                                     DomHelper.getLocation(mapElements[i]));
             }
             encounteredFieldMappings.add(field);
-            aggregateDefinition.addSplitMapping(group, field);
+            definition.addSplitMapping(group, field);
         }
 
         // read split fail message (if any)
         Element failMessageElement = DomHelper.getChildElement(splitElement, Constants.DEFINITION_NS, "failmessage");
         if (failMessageElement != null) {
             XMLizable failMessage = DomHelper.compileElementContent(failMessageElement);
-            aggregateDefinition.setSplitFailMessage(failMessage);
+            definition.setSplitFailMessage(failMessage);
         }
 
         // compile combine expression
@@ -93,13 +101,11 @@
             throw new Exception("Problem with combine expression defined at " +
                                 DomHelper.getLocation(combineElement) + ": " + e.getMessage());
         }
-        Class clazz = aggregateDefinition.getDatatype().getTypeClass();
+        Class clazz = definition.getDatatype().getTypeClass();
         if (combineExpr.getResultType() != null && !clazz.isAssignableFrom(combineExpr.getResultType())) {
             throw new Exception("The result of the combine expression should be " + clazz.getName() + ", at " +
                                 DomHelper.getLocation(combineElement));
         }
-        aggregateDefinition.setCombineExpression(combineExpr);
-
-        return aggregateDefinition;
+        definition.setCombineExpression(combineExpr);
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java Thu Feb 24 09:05:51 2005
@@ -58,9 +58,17 @@
         this.definition = definition;
     }
 
-    protected WidgetDefinition getDefinition() {
+    public WidgetDefinition getDefinition() {
         return this.definition;
     }
+    
+    public void initialize() {
+        Boolean value = this.definition.getInitialValue();
+        if (value != null) {
+            setValue(value);
+        }
+        super.initialize();
+    }
 
     public void readFromRequest(FormContext formContext) {
         if (!getCombinedState().isAcceptingInputs()) {
@@ -76,17 +84,6 @@
     }
 
     /**
-     * Always return <code>true</code> (an action has no validation)
-     * 
-     * TODO is there a use case for boolean fields having validators?
-     */
-    public boolean validate() {
-        // a boolean field is always valid
-        //return true;
-        return super.validate();
-    }
-
-    /**
      * Returns the validation error, if any. There will always be a validation error in case the
      * {@link #validate()} method returned false.
      */
@@ -169,7 +166,12 @@
     }
 
     public void broadcastEvent(WidgetEvent event) {
-        this.definition.fireValueChangedEvent((ValueChangedEvent)event);
-        fireValueChangedEvent((ValueChangedEvent)event);
+        if (event instanceof ValueChangedEvent) {
+            this.definition.fireValueChangedEvent((ValueChangedEvent)event);
+            fireValueChangedEvent((ValueChangedEvent)event);
+        } else {
+            // Other kinds of events
+            super.broadcastEvent(event);
+        }
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinition.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinition.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinition.java Thu Feb 24 09:05:51 2005
@@ -26,12 +26,24 @@
  */
 public class BooleanFieldDefinition extends AbstractWidgetDefinition {
     private ValueChangedListener listener;
+    
+    private Boolean initialValue;
 
     public Widget createInstance() {
         return new BooleanField(this);
     }
     
+    public void setInitialValue(Boolean value) {
+        checkMutable();
+        this.initialValue = value;
+    }
+    
+    public Boolean getInitialValue() {
+        return this.initialValue;
+    }
+    
     public void addValueChangedListener(ValueChangedListener listener) {
+        checkMutable();
         this.listener = WidgetEventMulticaster.add(this.listener, listener);
     }
     
@@ -46,6 +58,7 @@
     }
         
     public void setRequired(boolean required) {
+        checkMutable();
         throw new UnsupportedOperationException("The property 'required' is not available on widgets of type booleanfield.");
     }    
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -17,7 +17,9 @@
 
 import java.util.Iterator;
 
+import org.apache.cocoon.forms.Constants;
 import org.apache.cocoon.forms.event.ValueChangedListener;
+import org.apache.cocoon.forms.util.DomHelper;
 import org.w3c.dom.Element;
 
 /**
@@ -25,18 +27,24 @@
  * 
  * @version $Id$
  */
-public class BooleanFieldDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
+public final class BooleanFieldDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
     public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
         BooleanFieldDefinition definition = new BooleanFieldDefinition();
-        setCommonProperties(widgetElement, definition);
+        
+        super.setupDefinition(widgetElement, definition);
         setDisplayData(widgetElement, definition);
-        setValidators(widgetElement, definition);
         Iterator iter = buildEventListeners(widgetElement, "on-value-changed", ValueChangedListener.class).iterator();
         while (iter.hasNext()) {
             definition.addValueChangedListener((ValueChangedListener)iter.next());
         }
 
-        // TODO default value
+        // Initial value
+        Element initialValueElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "initial-value", false);
+        if (initialValueElement != null) {
+            Boolean initialValue = Boolean.valueOf(DomHelper.getElementText(initialValueElement));
+        }        
+
+        definition.makeImmutable();
         return definition;
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ClassDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ClassDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ClassDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ClassDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -24,13 +24,13 @@
  *
  * @version $Id$
  */
-public class ClassDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
+public final class ClassDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
 
     public WidgetDefinition buildWidgetDefinition(Element element) throws Exception {
         ClassDefinition definition = new ClassDefinition();
-        setCommonProperties(element, definition);
+        
+        super.setupDefinition(element, definition);
         setDisplayData(element, definition);
-        setValidators(element, definition);
 
         Element widgetsElement = DomHelper.getChildElement(element, Constants.DEFINITION_NS, "widgets", true);
         // All child elements of the widgets element are widgets
@@ -41,6 +41,7 @@
             definition.addWidgetDefinition(widgetDefinition);
         }
 
+        definition.makeImmutable();
         return definition;
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java Thu Feb 24 09:05:51 2005
@@ -125,9 +125,17 @@
         return this.fieldDefinition;
     }
 
-    protected WidgetDefinition getDefinition() {
+    public WidgetDefinition getDefinition() {
         return this.fieldDefinition;
     }
+    
+    public void initialize() {
+        Object value = this.fieldDefinition.getInitialValue();
+        if (value != null) {
+            setValue(value);
+        }
+        super.initialize();
+    }
 
     public Object getValue() {
         // if getValue() is called on this field while we're validating, then it's because a validation
@@ -197,8 +205,11 @@
             return;
 
         String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName());
-        // FIXME: Should we consider only non-null values, which allows to
-        // split a form across several screens?
+        // FIXME: Should we consider only non-null values?
+        // Although distinguishing an empty value (input present but blank) from a null value
+        // (input not present in the form) is possible, this distinction is not possible for
+        // several other kinds of widgets such as BooleanField or MultiValueField. So we keep
+        // it consistent with other widgets.
         //if (newEnteredValue != null) {
         readFromRequest(newEnteredValue);
         //}
@@ -398,8 +409,6 @@
         // generate selection list, if any
         if (selectionList != null) {
             selectionList.generateSaxFragment(contentHandler, locale);
-        } else if (getFieldDefinition().getSelectionList() != null) {
-            getFieldDefinition().getSelectionList().generateSaxFragment(contentHandler, locale);
         }
 
         // include some info about the datatype
@@ -481,7 +490,12 @@
     }
 
     public void broadcastEvent(WidgetEvent event) {
-        getFieldDefinition().fireValueChangedEvent((ValueChangedEvent)event);
-        fireValueChangedEvent((ValueChangedEvent)event);
+        if (event instanceof ValueChangedEvent) {
+            getFieldDefinition().fireValueChangedEvent((ValueChangedEvent)event);
+            fireValueChangedEvent((ValueChangedEvent)event);
+        } else {
+            // Other kinds of events
+            super.broadcastEvent(event);
+        }
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FieldDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FieldDefinition.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FieldDefinition.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FieldDefinition.java Thu Feb 24 09:05:51 2005
@@ -15,7 +15,6 @@
  */
 package org.apache.cocoon.forms.formmodel;
 
-import org.apache.cocoon.forms.event.CreateEvent;
 
 /**
  * The {@link WidgetDefinition} part of a Field widget, see {@link Field} for more information.
@@ -27,9 +26,8 @@
 
     public Widget createInstance() {
         Field field = new Field(this);
-        if (this.createListener != null) {
-            this.createListener.widgetCreated(new CreateEvent(field));
-        }
+        // Set the initial selection list, if any
+        field.setSelectionList(getSelectionList());
         return field;
     }
 
@@ -38,6 +36,7 @@
     }
 
     public void setRequired(boolean required) {
+        checkMutable();
         this.required = required;
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FieldDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FieldDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FieldDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FieldDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -15,11 +15,6 @@
  */
 package org.apache.cocoon.forms.formmodel;
 
-import java.util.Iterator;
-
-import org.apache.cocoon.forms.Constants;
-import org.apache.cocoon.forms.datatype.Datatype;
-import org.apache.cocoon.forms.event.ValueChangedListener;
 import org.apache.cocoon.forms.util.DomHelper;
 import org.w3c.dom.Element;
 
@@ -31,36 +26,17 @@
 public class FieldDefinitionBuilder extends AbstractDatatypeWidgetDefinitionBuilder {
 
     public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
-        FieldDefinition fieldDefinition = new FieldDefinition();
-        buildWidgetDefinition(fieldDefinition, widgetElement);
-        return fieldDefinition;
+        FieldDefinition definition = new FieldDefinition();
+        setupDefinition(widgetElement, definition);
+        definition.makeImmutable();
+        return definition;
     }
 
-    protected void buildWidgetDefinition(FieldDefinition fieldDefinition, Element widgetElement) throws Exception {
-        setCommonProperties(widgetElement, fieldDefinition);
-
-        Element datatypeElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "datatype");
-        if (datatypeElement == null) {
-            throw new Exception("A nested datatype element is required for the widget " 
-                                + widgetElement.getTagName() + " with id \"" + fieldDefinition.getId()
-                                + "\" at " + DomHelper.getLocation(widgetElement));
-        }
-
-        Datatype datatype = datatypeManager.createDatatype(datatypeElement, false);
-        fieldDefinition.setDatatype(datatype);
-
-        buildSelectionList(widgetElement, fieldDefinition);
-
-        Iterator iter = buildEventListeners(widgetElement, "on-value-changed", ValueChangedListener.class).iterator();
-        while (iter.hasNext()) {
-            fieldDefinition.addValueChangedListener((ValueChangedListener)iter.next());
-        }
-
-        setDisplayData(widgetElement, fieldDefinition);
-        setValidators(widgetElement, fieldDefinition);
-        setCreateListeners(widgetElement, fieldDefinition);
-
+    protected void setupDefinition(Element widgetElement, FieldDefinition definition) throws Exception {
+        super.setupDefinition(widgetElement, definition);
+        
+        // parse "@required"
         boolean required = DomHelper.getAttributeAsBoolean(widgetElement, "required", false);
-        fieldDefinition.setRequired(required);
+        definition.setRequired(required);
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java Thu Feb 24 09:05:51 2005
@@ -56,8 +56,28 @@
         super(definition);
         this.definition = definition;
     }
+    
+    /**
+     * Initialize the form by recursively initializing all its children. Any events occuring within the
+     * initialization phase are buffered and fired after initialization is complete, so that any action
+     * from a widget on another one occurs after that other widget has been given the opportunity to
+     * initialize itself.
+     */
+    public void initialize() {
+        try {
+            // Start buffering events
+            this.bufferEvents = true;
+            super.initialize();
+            // Fire events, still buffering them: this ensures they will be handled in the same
+            // order as they were added.
+            fireEvents();
+        } finally {
+            // Stop buffering events
+            this.bufferEvents = false;
+        }
+    }
 
-    protected WidgetDefinition getDefinition() {
+    public WidgetDefinition getDefinition() {
         return this.definition;
     }
 

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -24,13 +24,13 @@
  * 
  * @version $Id$
  */
-public class FormDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
+public final class FormDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
 
     public WidgetDefinition buildWidgetDefinition(Element formElement) throws Exception {
         FormDefinition formDefinition = new FormDefinition();
-        setCommonProperties(formElement, formDefinition);
+        
+        super.setupDefinition(formElement, formDefinition);
         setDisplayData(formElement, formDefinition);
-        setValidators(formElement, formDefinition);
 
         Element widgetsElement = DomHelper.getChildElement(formElement, Constants.DEFINITION_NS, "widgets", true);
         // All child elements of the widgets element are widgets
@@ -43,6 +43,7 @@
 
         formDefinition.resolve();
 
+        formDefinition.makeImmutable();
         return formDefinition;
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Group.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Group.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Group.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Group.java Thu Feb 24 09:05:51 2005
@@ -31,7 +31,7 @@
         this.definition = definition;
     }
     
-    protected WidgetDefinition getDefinition() {
+    public WidgetDefinition getDefinition() {
         return this.definition;
     }
     

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -24,13 +24,13 @@
  *
  * @version $Id$
  */
-public class GroupDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
+public final class GroupDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
 
     public WidgetDefinition buildWidgetDefinition(Element element) throws Exception {
         GroupDefinition definition = new GroupDefinition();
-        setCommonProperties(element, definition);
+        
+        super.setupDefinition(element, definition);
         setDisplayData(element, definition);
-        setValidators(element, definition);
 
         Element widgetsElement = DomHelper.getChildElement(element, Constants.DEFINITION_NS, "widgets", true);
         // All child elements of the widgets element are widgets
@@ -41,6 +41,7 @@
             definition.addWidgetDefinition(widgetDefinition);
         }
 
+        definition.makeImmutable();
         return definition;
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java Thu Feb 24 09:05:51 2005
@@ -48,7 +48,7 @@
         this.definition = definition;
     }
 
-    protected WidgetDefinition getDefinition() {
+    public WidgetDefinition getDefinition() {
         return this.definition;
     }
 

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MessagesDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MessagesDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MessagesDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MessagesDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -22,11 +22,12 @@
  * 
  * @version $Id$
  */
-public class MessagesDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
+public final class MessagesDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
     public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
         MessagesDefinition messagesDefinition = new MessagesDefinition();
-        setCommonProperties(widgetElement, messagesDefinition);
+        super.setupDefinition(widgetElement, messagesDefinition);
         setDisplayData(widgetElement, messagesDefinition);
+        messagesDefinition.makeImmutable();
         return messagesDefinition;
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java Thu Feb 24 09:05:51 2005
@@ -49,7 +49,7 @@
  *
  * @version $Id$
  */
-public class MultiValueField extends AbstractWidget implements ValidationErrorAware, SelectableWidget {
+public class MultiValueField extends AbstractWidget implements ValidationErrorAware, SelectableWidget, DataWidget {
 
     private static final String MULTIVALUEFIELD_EL = "multivaluefield";
     private static final String VALUES_EL = "values";
@@ -68,7 +68,7 @@
         this.definition = definition;
     }
 
-    protected WidgetDefinition getDefinition() {
+    public WidgetDefinition getDefinition() {
         return definition;
     }
 
@@ -147,11 +147,7 @@
         contentHandler.endElement(Constants.INSTANCE_NS, VALUES_EL, Constants.INSTANCE_PREFIX_COLON + VALUES_EL);
 
         // the selection list (a MultiValueField has per definition always a SelectionList)
-        if (this.selectionList != null) {
-            this.selectionList.generateSaxFragment(contentHandler, locale);
-        } else {
-            definition.getSelectionList().generateSaxFragment(contentHandler, locale);
-        }
+        this.selectionList.generateSaxFragment(contentHandler, locale);
 
         // validation message element
         if (validationError != null) {
@@ -190,8 +186,11 @@
      * @param selectionList The new selection list.
      */
     public void setSelectionList(SelectionList selectionList) {
-        if (selectionList != null &&
-            selectionList.getDatatype() != null &&
+        if (selectionList == null) {
+            throw new IllegalArgumentException("An MultiValueField's selection list cannot be null.");
+        }
+        
+        if (selectionList.getDatatype() != null &&
             selectionList.getDatatype() != definition.getDatatype()) {
 
             throw new RuntimeException("Tried to assign a SelectionList that is not associated with this widget's datatype.");
@@ -233,7 +232,12 @@
     }
 
     public void broadcastEvent(WidgetEvent event) {
-        this.definition.fireValueChangedEvent((ValueChangedEvent)event);
+        if (event instanceof ValueChangedEvent) {
+            this.definition.fireValueChangedEvent((ValueChangedEvent)event);
+        } else {
+            // Other kinds of events
+            super.broadcastEvent(event);
+        }
     }
 
     public ValidationError getValidationError() {

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinition.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinition.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinition.java Thu Feb 24 09:05:51 2005
@@ -22,7 +22,10 @@
  */
 public class MultiValueFieldDefinition extends FieldDefinition {
     public Widget createInstance() {
-        return new MultiValueField(this);
+        MultiValueField field =  new MultiValueField(this);
+        // Set the initial selection list, if any
+        field.setSelectionList(getSelectionList());
+        return field;
     }
     
 	public void setRequired(boolean required) {

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -15,13 +15,8 @@
  */
 package org.apache.cocoon.forms.formmodel;
 
-import java.util.Iterator;
-
-import org.w3c.dom.Element;
-import org.apache.cocoon.forms.Constants;
-import org.apache.cocoon.forms.datatype.Datatype;
-import org.apache.cocoon.forms.event.ValueChangedListener;
 import org.apache.cocoon.forms.util.DomHelper;
+import org.w3c.dom.Element;
 
 /**
  * Builds {@link MultiValueFieldDefinition}s.
@@ -29,30 +24,14 @@
  * @version $Id$
  */
 public class MultiValueFieldDefinitionBuilder extends AbstractDatatypeWidgetDefinitionBuilder {
+
     public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
         MultiValueFieldDefinition definition = new MultiValueFieldDefinition();
-        setCommonProperties(widgetElement, definition);
-        setDisplayData(widgetElement, definition);
-        setValidators(widgetElement, definition);
-
-        Element datatypeElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "datatype");
-        if (datatypeElement == null) {
-            throw new Exception("A nested datatype element is required for the widget "
-                                + widgetElement.getTagName() + " with id \"" + definition.getId()
-                                + "\" at " + DomHelper.getLocation(widgetElement));
-        }
-
-        Datatype datatype = datatypeManager.createDatatype(datatypeElement, true);
-        definition.setDatatype(datatype);
-
-        boolean hasSelectionList = buildSelectionList(widgetElement, definition);
-        if (!hasSelectionList)
-            throw new Exception("Error: multivaluefields always require a selectionlist at " + DomHelper.getLocation(widgetElement));
-
-        Iterator iter = buildEventListeners(widgetElement, "on-value-changed", ValueChangedListener.class).iterator();
-        while (iter.hasNext()) {
-            definition.addValueChangedListener((ValueChangedListener)iter.next());
-        }
+        setupDefinition(widgetElement, definition);
+        if (definition.getSelectionList() == null)
+            throw new Exception("Error: multivaluefield always require a selectionlist at " +
+                    DomHelper.getLocation(widgetElement));
+        definition.makeImmutable();
         return definition;
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/NewDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/NewDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/NewDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/NewDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -26,7 +26,8 @@
 
     public WidgetDefinition buildWidgetDefinition(Element element) throws Exception {
         NewDefinition definition = new NewDefinition();
-        setCommonProperties(element, definition);
+        super.setupDefinition(element, definition);
+        definition.makeImmutable();
         return definition;
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java Thu Feb 24 09:05:51 2005
@@ -51,7 +51,7 @@
         this.definition = definition;
     }
 
-    protected WidgetDefinition getDefinition() {
+    public WidgetDefinition getDefinition() {
         return definition;
     }
 

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/OutputDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/OutputDefinitionBuilder.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/OutputDefinitionBuilder.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/OutputDefinitionBuilder.java Thu Feb 24 09:05:51 2005
@@ -17,9 +17,6 @@
 package org.apache.cocoon.forms.formmodel;
 
 import org.w3c.dom.Element;
-import org.apache.cocoon.forms.Constants;
-import org.apache.cocoon.forms.datatype.Datatype;
-import org.apache.cocoon.forms.util.DomHelper;
 
 /**
  * Builds {@link OutputDefinition}s.
@@ -27,22 +24,11 @@
  * @version $Id$
  */
 public class OutputDefinitionBuilder extends AbstractDatatypeWidgetDefinitionBuilder {
+
     public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
         OutputDefinition definition = new OutputDefinition();
-        setCommonProperties(widgetElement, definition);
-
-        Element datatypeElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "datatype");
-        if (datatypeElement == null) {
-            throw new Exception("A nested datatype element is required for the widget " 
-                                + widgetElement.getTagName() + " with id \"" + definition.getId()
-                                + "\" at " + DomHelper.getLocation(widgetElement));
-        }
-
-        Datatype datatype = datatypeManager.createDatatype(datatypeElement, false);
-        definition.setDatatype(datatype);
-
-        setDisplayData(widgetElement, definition);
-
+        setupDefinition(widgetElement, definition);
+        definition.makeImmutable();
         return definition;
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java?view=diff&r1=155210&r2=155211
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java (original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java Thu Feb 24 09:05:51 2005
@@ -50,13 +50,23 @@
     public Repeater(RepeaterDefinition repeaterDefinition) {
         super(repeaterDefinition);
         this.definition = repeaterDefinition;
-        // setup initial size
-        removeRows();
+        // Setup initial size. Do not call addRow() as it will call initialize()
+        // on the newly created rows, which is not what we want here.
+        for (int i = 0; i < this.definition.getInitialSize(); i++) {
+            rows.add(new RepeaterRow(definition));
+        }
     }
 
     public WidgetDefinition getDefinition() {
         return definition;
     }
+    
+    public void initialize() {
+        for (int i = 0; i < this.rows.size(); i++) {
+            ((RepeaterRow)rows.get(i)).initialize();
+        }
+        super.initialize();
+    }
 
     public int getSize() {
         return rows.size();
@@ -157,11 +167,19 @@
             this.rows.set(index, temp);
         }
     }
-
+    
     /**
-     * Clears all rows from the repeater and go back to the initial size
+     * @deprecated {@see #clear()}
+     *
      */
     public void removeRows() {
+        clear();
+    }
+    
+    /**
+     * Clears all rows from the repeater and go back to the initial size
+     */
+    public void clear() {
         rows.clear();
         
         // and reset to initial size
@@ -321,7 +339,7 @@
 //            return Repeater.this.getLocation();
 //        }
 //        
-        protected WidgetDefinition getDefinition() {
+        public WidgetDefinition getDefinition() {
             return Repeater.this.definition;
         }
 
@@ -333,14 +351,16 @@
         public Form getForm() {
             return Repeater.this.getForm();
         }
-
-//        public String getNamespace() {
-//            return getParent().getNamespace() + "." + getId();
-//        }
-//
-//        public String getFullyQualifiedId() {
-//            return getParent().getNamespace() + "." + getId();
-//        }
+        
+        public void initialize() {
+            // Initialize children but don't call super.initialize() that would call the repeater's
+            // on-create handlers for each row.
+            // FIXME(SW): add an 'on-create-row' handler?
+            Iterator it = this.getChildren();
+            while(it.hasNext()) {
+              ((Widget)it.next()).initialize();
+            }
+        }
 
         public boolean validate() {
             // Validate only child widtgets, as the definition's validators are those of the parent repeater
@@ -365,19 +385,6 @@
                 throws SAXException {
             // this widget has its display-data generated in the context of the repeater
         }
-                
-//        //TODO: reuse available implementation on superclass       
-//        public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
-//            AttributesImpl rowAttrs = new AttributesImpl();
-//            rowAttrs.addCDATAAttribute("id", getFullyQualifiedId());
-//            contentHandler.startElement(Constants.INSTANCE_NS, ROW_EL, Constants.INSTANCE_PREFIX_COLON + ROW_EL, rowAttrs);
-//            Iterator widgetIt = widgets.iterator();
-//            while (widgetIt.hasNext()) {
-//                Widget widget = (Widget)widgetIt.next();
-//                widget.generateSaxFragment(contentHandler, locale);
-//            }
-//            contentHandler.endElement(Constants.INSTANCE_NS, ROW_EL, Constants.INSTANCE_PREFIX_COLON + ROW_EL);
-//        }
         
         public void broadcastEvent(WidgetEvent event) {
             throw new UnsupportedOperationException("Widget " + this.getRequestParameterName() + " doesn't handle events.");



Mime
View raw message