cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r231335 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel: AbstractWidget.java Action.java AggregateField.java BooleanField.java CaptchaField.java Field.java Form.java MultiValueField.java Repeater.java
Date Wed, 10 Aug 2005 21:40:44 GMT
Author: vgritsenko
Date: Wed Aug 10 14:40:35 2005
New Revision: 231335

URL: http://svn.apache.org/viewcvs?rev=231335&view=rev
Log:
cosmetic changes

Modified:
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Action.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AggregateField.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/BooleanField.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/CaptchaField.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Field.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java?rev=231335&r1=231334&r2=231335&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java Wed
Aug 10 14:40:35 2005
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2005 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,12 +33,12 @@
 /**
  * Abstract base class for Widget implementations. Provides functionality
  * common to many widgets.
- * 
+ *
  * @version $Id$
  */
 public abstract class AbstractWidget implements Widget {
 
-    /** 
+    /**
      * Containing parent-widget to this widget.
      * NOTE: avoid directly accessing this member since subclasses can mask this
      * property through own implemented getParent()
@@ -70,6 +70,7 @@
      */
     protected boolean wasValid = true;
 
+
     protected AbstractWidget(AbstractWidgetDefinition definition) {
         this.state = definition.getState();
     }
@@ -94,29 +95,29 @@
         return getId();
     }
 
-    /** 
+    /**
      * Concrete subclasses should allow access to their underlaying Definition
      * through this method.
      *
-     * If subclasses decide to return <code>null</code> they should also organize

+     * If subclasses decide to return <code>null</code> they should also organize
      * own implementations of {@link #getId()}, {@link #getLocation()},
      * {@link #validate()}, {@link #generateLabel(ContentHandler)} and
      * {@link #generateDisplayData(ContentHandler)} to avoid NPE's.
-     * 
-     * @return the widgetDefinition from which this widget was instantiated. 
+     *
+     * @return the widgetDefinition from which this widget was instantiated.
      *        (@link WidgetDefinition#createInstance()}
      */
     public abstract WidgetDefinition getDefinition();
 
     /**
-     * @return the location-information (file, line and column) where this widget was 
+     * @return the location-information (file, line and column) where this widget was
      * configured.
      */
     public String getLocation() {
         return getDefinition().getLocation();
     }
 
-    /** 
+    /**
      * @return The parent-widget of this widget.
      */
     // This method is final in order for other methods in this class to use this.parent
@@ -124,20 +125,22 @@
         return this.parent;
     }
 
-    /** 
+    /**
      * Sets the parent-widget of this widget.
      * This is a write-once property.
-     * 
+     *
      * @param widget the parent-widget of this one.
      * @throws IllegalStateException when the parent had already been set.
-     */    
+     */
     public void setParent(Widget widget) {
-        if (this.parent != null) throw new IllegalStateException("The parent of widget "
+ getRequestParameterName() + " should only be set once.");
+        if (this.parent != null) {
+            throw new IllegalStateException("The parent of widget " + getRequestParameterName()
+ " should only be set once.");
+        }
         this.parent = widget;
     }
 
     /**
-     * @return the form where this widget belongs to.  
+     * @return the form where this widget belongs to.
      */
     public Form getForm() {
         if (this.form == null) {
@@ -168,7 +171,7 @@
     public WidgetState getCombinedState() {
         if (this.parent == null) {
             return this.state;
-        } 
+        }
         return WidgetState.strictest(this.state, this.parent.getCombinedState());
     }
 
@@ -191,7 +194,7 @@
     }
     
     public String getRequestParameterName() {
-        
+
         if (this.parent == null) {
             return getId();
         }
@@ -216,11 +219,12 @@
 
     public Widget lookupWidget(String path) {
 
-        if (path == null || path.equals(""))
+        if (path == null || path.equals("")) {
             return this;
+        }
 
         Widget relativeWidget;
-        String relativePath = null;        
+        String relativePath = null;
         int sepPosition = path.indexOf("" + Widget.PATH_SEPARATOR);
 
         if (sepPosition < 0) {
@@ -237,7 +241,7 @@
                 relativePath = path.substring(3);
             } else {
                 String childId = path.substring(0, sepPosition );
-                relativeWidget = getChild(childId);            
+                relativeWidget = getChild(childId);
                 relativePath = path.substring(sepPosition+1);
             }
         }
@@ -247,9 +251,9 @@
     }
 
     /**
-     * Concrete widgets that contain actual child widgets should override to 
+     * Concrete widgets that contain actual child widgets should override to
      * return the actual child-widget.
-     * 
+     *
      * @param id of the child-widget
      * @return <code>null</code> if not overriden.
      */
@@ -276,7 +280,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * Abstract implementation throws a {@link UnsupportedOperationException}.
      * Concrete subclass widgets need to override when supporting event broadcasting.
      */
@@ -290,7 +294,7 @@
 
     /**
      * Add a validator to this widget instance.
-     * 
+     *
      * @param validator
      */
     public void addValidator(WidgetValidator validator) {
@@ -302,7 +306,7 @@
 
     /**
      * Remove a validator from this widget instance
-     * 
+     *
      * @param validator
      * @return <code>true</code> if the validator was found.
      */
@@ -328,7 +332,7 @@
             // Failed
             this.wasValid = false;
             return false;
-        } 
+        }
         // Definition successful, test local validators
         if (this.validators == null) {
             // No local validators
@@ -360,13 +364,13 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * Delegates to the {@link #getDefinition()} to generate the 'label' part of
-     * the display-data of this widget.  
-     * 
+     * the display-data of this widget.
+     *
      * Subclasses should override if the getDefinition can return <code>null</code>
      * to avoid NPE's
-     * 
+     *
      * @param contentHandler
      * @throws SAXException
      */
@@ -377,12 +381,12 @@
     }
 
     /**
-     * Generates nested additional content nested inside the main element for this 
+     * Generates nested additional content nested inside the main element for this
      * widget which is generated by {@link #generateSaxFragment(ContentHandler, Locale)}
-     * 
+     *
      * The implementation on the AbstractWidget level inserts no additional XML.
      * Subclasses need to override to insert widget specific content.
-     * 
+     *
      * @param contentHandler to send the SAX events to
      * @param locale in which context potential content needs to be put.
      * @throws SAXException
@@ -391,26 +395,26 @@
         // Do nothing
     }
 
-    /** 
+    /**
      * The XML element name used in {@link #generateSaxFragment(ContentHandler, Locale)}
      * to produce the wrapping element for all the XML-instance-content of this Widget.
-     * 
-     * @return the main elementname for this widget's sax-fragment. 
+     *
+     * @return the main elementname for this widget's sax-fragment.
      */
     protected abstract String getXMLElementName();
 
-    /** 
+    /**
      * The XML attributes used in {@link #generateSaxFragment(ContentHandler, Locale)}
      * to be placed on the wrapping element for all the XML-instance-content of this Widget.
-     * 
+     *
      * This automatically adds @id={@link #getRequestParameterName()} to that element.
      * Concrete subclasses should call super.getXMLElementAttributes and possibly
      * add additional attributes.
-     * 
-     * Note: the @id is not added for those widgets who's getId() returns <code>null</code>

+     *
+     * Note: the @id is not added for those widgets who's getId() returns <code>null</code>
      * (e.g. top-level container widgets like 'form').  The contract of returning a non-null
      * {@link AttributesImpl} is however maintained.
-     * 
+     *
      * @return the attributes for the main element for this widget's sax-fragment.
      */
     protected AttributesImpl getXMLElementAttributes() {
@@ -432,14 +436,14 @@
     /**
      * Delegates to the {@link #getDefinition()} of this widget to generate a common
      * set of 'display' data. (i.e. help, label, hint,...)
-     * 
+     *
      * Subclasses should override if the getDefinition can return <code>null</code>
      * to avoid NPE's.
-     * 
+     *
      * @param contentHandler where to send the SAX events to.
      * @throws SAXException
-     * 
-     * @see WidgetDefinition#generateDisplayData(ContentHandler) 
+     *
+     * @see WidgetDefinition#generateDisplayData(ContentHandler)
      */
     protected void generateDisplayData(ContentHandler contentHandler) throws SAXException
{
         getDefinition().generateDisplayData(contentHandler);
@@ -447,26 +451,26 @@
 
     /**
      * {@inheritDoc}
-     * 
-     * This will generate some standard XML consisting of a simple wrapper 
+     *
+     * This will generate some standard XML consisting of a simple wrapper
      * element (name provided by {@link #getXMLElementName()}) with attributes
-     * (provided by {@link #getXMLElementAttributes()} around anything injected 
+     * (provided by {@link #getXMLElementAttributes()} around anything injected
      * in by both {@link #generateDisplayData(ContentHandler)} and
      * {@link #generateItemSaxFragment(ContentHandler, Locale)}.
-     * 
+     *
      * <pre>
      * &lt;fi:{@link #getXMLElementName()} {@link #getXMLElementAttributes()} &gt;
      *   {@link #generateDisplayData(ContentHandler)} (i.e. help, label, ...)
-     * 
+     *
      *   {@link #generateItemSaxFragment(ContentHandler, Locale)}
-     * &lt;/fi:{@link #getXMLElementName()} &gt; 
+     * &lt;/fi:{@link #getXMLElementName()} &gt;
      * </pre>
-     * 
+     *
      * @param contentHandler to send the SAX events to
      * @param locale in which context potential content needs to be put.
-     * @throws SAXException 
+     * @throws SAXException
      */
-    public void generateSaxFragment(ContentHandler contentHandler, Locale locale)    
+    public void generateSaxFragment(ContentHandler contentHandler, Locale locale)
     throws SAXException {
 
         if (getCombinedState().isDisplayingValues()) {
@@ -492,13 +496,17 @@
 
 	public Object getAttribute(String name) {
         Object result = null;
-        
+
         // First check locally
-        if (this.attributes != null) result = this.attributes.get(name);
-        
+        if (this.attributes != null) {
+            result = this.attributes.get(name);
+        }
+
         // Fall back to the definition's attributes
-        if (result == null) result = getDefinition().getAttribute(name);
-        
+        if (result == null) {
+            result = getDefinition().getAttribute(name);
+        }
+
         return result;
     }
 
@@ -514,7 +522,7 @@
             this.attributes.remove(name);
         }
     }
-    
+
     public String toString() {
         String className = this.getClass().getName();
         int last = className.lastIndexOf('.');

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Action.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Action.java?rev=231335&r1=231334&r2=231335&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Action.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Action.java Wed Aug 10
14:40:35 2005
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,14 +27,16 @@
  * or as a hidden field which gets its value set by javascript. The Action widget will generate
its associated
  * ActionEvent when a requestparameter is present with as name the id of this Action widget,
and as
  * value a non-empty value.
- * 
+ *
  * @version $Id$
  */
 public class Action extends AbstractWidget implements ActionListenerEnabled {
+
     private final ActionDefinition definition;
     /** Additional listeners to those defined as part of the widget definition (if any).
*/
     private ActionListener listener;
 
+
     public Action(ActionDefinition definition) {
         super(definition);
         this.definition = definition;
@@ -45,8 +47,9 @@
     }
 
     public void readFromRequest(final FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isAcceptingInputs()) {
             return;
+        }
 
         Form form = getForm();
 
@@ -73,7 +76,6 @@
 
         if (form.getSubmitWidget() == this) {
             form.addWidgetEvent(new ActionEvent(this, definition.getActionCommand()));
-
             handleActivate();
         }
     }
@@ -89,8 +91,8 @@
 
     /**
      * Always return <code>true</code> (an action has no validation)
-     * 
-     * TODO is there a use case for actions having validators?
+     *
+     * <br>TODO is there a use case for actions having validators?
      */
     public boolean validate() {
         return true;
@@ -102,15 +104,15 @@
     public boolean isValid() {
         return true;
     }
-    
+
     private static final String ACTION_EL = "action";
 
     /**
      * @return "action"
      */
-    public String getXMLElementName() {        
+    public String getXMLElementName() {
         return ACTION_EL;
-    }  
+    }
 
     /**
      * Adds a ActionListener to this widget instance. Listeners defined
@@ -140,5 +142,4 @@
             super.broadcastEvent(event);
         }
     }
-
 }

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AggregateField.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AggregateField.java?rev=231335&r1=231334&r2=231335&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AggregateField.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AggregateField.java Wed
Aug 10 14:40:35 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -53,6 +53,8 @@
  */
 public class AggregateField extends Field implements ContainerWidget {
 
+    private static final String AGGREGATEFIELD_EL = "aggregatefield";
+
     /**
      * List of nested fields
      */
@@ -71,7 +73,7 @@
     public final AggregateFieldDefinition getAggregateFieldDefinition() {
         return (AggregateFieldDefinition)getDefinition();
     }
-    
+
     public void initialize() {
         this.selectionList = getAggregateFieldDefinition().getSelectionList();
     }
@@ -99,8 +101,9 @@
     }
 
     public void readFromRequest(FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isAcceptingInputs()) {
             return;
+        }
 
         String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName());
         if (newEnteredValue != null) {
@@ -198,6 +201,7 @@
             this.wasValid = true;
             return true;
         }
+
         if (enteredValue != null && !fieldsHaveValues()) {
             XMLizable failMessage = getAggregateFieldDefinition().getSplitFailMessage();
             if (failMessage != null) {
@@ -229,8 +233,6 @@
 
         return super.validate();
     }
-
-    private static final String AGGREGATEFIELD_EL = "aggregatefield";
 
     /**
      * @return "aggregatefield"

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/BooleanField.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/BooleanField.java?rev=231335&r1=231334&r2=231335&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/BooleanField.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/BooleanField.java Wed
Aug 10 14:40:35 2005
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,10 +38,11 @@
  * has no purpose here (there would always be only 2 choices: true or false),
  * and the manner in which the request parameter of this widget is interpreted
  * is different (missing or empty request parameter means 'false', rather than null value).
- * 
+ *
  * @version $Id$
  */
-public class BooleanField extends AbstractWidget implements ValidationErrorAware, ValueChangedListenerEnabled
{
+public class BooleanField extends AbstractWidget
+                          implements ValidationErrorAware, ValueChangedListenerEnabled {
 
     private static final String BOOLEAN_FIELD_EL = "booleanfield";
     private static final String VALUE_EL = "value";
@@ -55,6 +56,7 @@
     private ValueChangedListener listener;
     protected ValidationError validationError;
 
+
     public BooleanField(BooleanFieldDefinition definition) {
         super(definition);
         this.definition = definition;
@@ -63,7 +65,7 @@
     public WidgetDefinition getDefinition() {
         return this.definition;
     }
-    
+
     public void initialize() {
         Boolean value = this.definition.getInitialValue();
         if (value != null) {
@@ -76,6 +78,7 @@
         if (!getCombinedState().isAcceptingInputs()) {
             return;
         }
+
         validationError = null;
         Object oldValue = value;
         String param = formContext.getRequest().getParameter(getRequestParameterName());

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/CaptchaField.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/CaptchaField.java?rev=231335&r1=231334&r2=231335&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/CaptchaField.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/CaptchaField.java Wed
Aug 10 14:40:35 2005
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2005 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,7 +33,7 @@
 
 /**
  * A {@link Field} for CAPTCHA validation. Upon generation, a secret random string is stored
- * in a session attribute having a randomly generated name, for use by a 
+ * in a session attribute having a randomly generated name, for use by a
  * {@link org.apache.cocoon.forms.validation.impl.CaptchaValidator}.
  * <br>
  * Usage sample:
@@ -46,8 +46,8 @@
       &lt;/fd:validation>
     &lt;/fd:captcha>
  * </pre>
- * 
- * @see http://www.captcha.net/
+ *
+ * @see <a href="http://www.captcha.net/">captcha.net</a>
  * @version CVS $Id$
  */
 public class CaptchaField extends Field {
@@ -57,7 +57,7 @@
     private static final String IMAGE_EL = "captcha-image";
     private static final String SECRET_CHARS = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
     private static final int SESSION_ATTR_NAME_LENGTH = 6;
-    
+
     private Context avalonContext;
     private int length;
 
@@ -85,12 +85,12 @@
         this.avalonContext = avalonContext;
         this.length = fieldDefinition.getLength();
     }
-    
+
     private String generateSecret() {
         StringBuffer secret = new StringBuffer(length);
         for (int n = 0 ; n < length ; n++) {
             int randomnumber = random.nextInt(SECRET_CHARS.length());
-            secret.append(SECRET_CHARS.charAt(randomnumber)); 
+            secret.append(SECRET_CHARS.charAt(randomnumber));
         }
         return secret.toString();
     }
@@ -116,5 +116,4 @@
         contentHandler.startElement(Constants.INSTANCE_NS, IMAGE_EL, Constants.INSTANCE_PREFIX_COLON
+ IMAGE_EL, attrs);
         contentHandler.endElement(Constants.INSTANCE_NS, IMAGE_EL, Constants.INSTANCE_PREFIX_COLON
+ IMAGE_EL);
     }
-    
 }

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Field.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Field.java?rev=231335&r1=231334&r2=231335&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Field.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Field.java Wed Aug 10
14:40:35 2005
@@ -45,8 +45,8 @@
  * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
  * @version $Id$
  */
-public class Field extends AbstractWidget implements ValidationErrorAware, DataWidget, SelectableWidget,
-        ValueChangedListenerEnabled {
+public class Field extends AbstractWidget
+                   implements ValidationErrorAware, DataWidget, SelectableWidget, ValueChangedListenerEnabled
{
 
     private static final String FIELD_EL = "field";
     private static final String VALUE_EL = "value";
@@ -107,13 +107,12 @@
 
     // At startup, we have no value to parse (both enteredValue and value are null),
     // but need to validate (e.g. error if field is required)
-    protected int valueState = VALUE_PARSED;
-
-
     /**
      * Transient widget processing state indicating that the widget is currently validating
      * (used to avoid endless loops when a validator calls getValue)
      */
+    protected int valueState = VALUE_PARSED;
+
     protected ValidationError validationError;
 
 
@@ -129,7 +128,7 @@
     public WidgetDefinition getDefinition() {
         return this.fieldDefinition;
     }
-    
+
     public void initialize() {
         Object value = this.fieldDefinition.getInitialValue();
         if (value != null) {
@@ -193,7 +192,7 @@
             // Do we need to call listeners? If yes, keep (and parse if needed) old value.
             boolean callListeners = changed && hasValueChangedListeners();
             Object oldValue = callListeners ? getValue() : null;
-            
+
             this.value = newValue;
             this.validationError = null;
             // Force validation, even if set by the application
@@ -212,8 +211,9 @@
     }
 
     public void readFromRequest(FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isAcceptingInputs()) {
             return;
+        }
 
         String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName());
         // FIXME: Should we consider only non-null values?
@@ -224,7 +224,6 @@
         //if (newEnteredValue != null) {
         readFromRequest(newEnteredValue);
         //}
-
     }
 
     protected void readFromRequest(String newEnteredValue) {
@@ -245,14 +244,15 @@
         } else {
             changed = !enteredValue.equals(newEnteredValue);
         }
+
         if (changed) {
             ValidationError oldError = this.validationError;
-            
+
             // If we have some value-changed listeners, we must make sure the current value
has been
             // parsed, to fill the event. Otherwise, we don't need to spend that extra CPU
time.
             boolean hasListeners = hasValueChangedListeners();
             Object oldValue = hasListeners ? getValue() : null;
-            
+
             enteredValue = newEnteredValue;
             validationError = null;
             value = null;
@@ -302,7 +302,7 @@
         }
 
         this.wasValid = this.validationError == null;
-        return this.validationError == null;
+        return this.wasValid;
     }
 
     /**
@@ -318,9 +318,11 @@
         if (this.valueState != VALUE_UNPARSED) {
             throw new IllegalStateException("Field is not in UNPARSED state (" + this.valueState
+ ")");
         }
+
         // Clear value, it will be recomputed
         this.value = null;
         this.validationError = null;
+
         if (this.enteredValue != null) {
             // Parse the value
             ConversionResult conversionResult = getDatatype().convertFromString(this.enteredValue,
getForm().getLocale());
@@ -346,7 +348,6 @@
      * validation failed.
      */
     private void doValidate() {
-
         if (this.valueState != VALUE_PARSED) {
             throw new IllegalStateException("Field is not in PARSED state (" + this.valueState
+ ")");
         }

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java?rev=231335&r1=231334&r2=231335&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java Wed Aug 10
14:40:35 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -40,7 +40,10 @@
  * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
  * @version $Id$
  */
-public class Form extends AbstractContainerWidget implements ValidationErrorAware {
+public class Form extends AbstractContainerWidget
+                  implements ValidationErrorAware {
+
+    private static final String FORM_EL = "form";
 
     private final FormDefinition definition;
 
@@ -56,17 +59,18 @@
     //to read their value before events get fired.
     private boolean bufferEvents = false;
     private CursorableLinkedList events;
-    
+
     // Widgets that need to be updated in the client when in AJAX mode
     private Set updatedWidgets;
     // Widgets that have at least one descendant that has to be updated
     private Set childUpdatedWidgets;
 
+
     public Form(FormDefinition definition) {
         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
@@ -111,7 +115,7 @@
             event.getSourceWidget().broadcastEvent(event);
         }
     }
-    
+
     /**
      * Mark a widget as being updated. When it Ajax mode, only updated widgets will be redisplayed
      * 
@@ -140,7 +144,7 @@
     public Set getUpdatedWidgetIds() {
         return this.updatedWidgets;
     }
-    
+
     public Set getChildUpdatedWidgetIds() {
         return this.childUpdatedWidgets;
     }
@@ -261,7 +265,7 @@
             this.updatedWidgets = new HashSet();
             this.childUpdatedWidgets = new HashSet();
         }
-        
+
         // Fire the binding phase events
         fireEvents();
 
@@ -349,7 +353,7 @@
         // let all individual widgets read their value from the request object
         super.readFromRequest(formContext);
     }
-    
+
     /**
      * Set a validation error on this field. This allows the form to be externally marked
as invalid by
      * application logic.
@@ -366,7 +370,7 @@
     public void setValidationError(ValidationError error) {
         this.validationError = error;
     }
-    
+
     /**
      * Performs validation phase of form processing.
      */
@@ -395,8 +399,6 @@
         this.wasValid = this.isValid && this.validationError == null;
         return this.wasValid;
     }
-
-    private static final String FORM_EL = "form";
 
     public String getXMLElementName() {
         return FORM_EL;

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java?rev=231335&r1=231334&r2=231335&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
(original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
Wed Aug 10 14:40:35 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -49,7 +49,8 @@
  *
  * @version $Id$
  */
-public class MultiValueField extends AbstractWidget implements ValidationErrorAware, SelectableWidget,
DataWidget {
+public class MultiValueField extends AbstractWidget
+                             implements ValidationErrorAware, SelectableWidget, DataWidget
{
 
     private static final String MULTIVALUEFIELD_EL = "multivaluefield";
     private static final String VALUES_EL = "values";
@@ -67,7 +68,7 @@
         super(definition);
         this.definition = definition;
     }
-    
+
     public void initialize() {
         this.selectionList = this.definition.getSelectionList();
         super.initialize();
@@ -121,10 +122,10 @@
 
         if (values != null) {
             validationError = definition.getDatatype().validate(values, new ExpressionContextImpl(this));
-        }
-        else {
+        } else {
             validationError = new ValidationError(new I18nMessage("multivaluefield.conversionfailed",
Constants.I18N_CATALOGUE));
         }
+
         this.wasValid = validationError == null ? super.validate() : false;
         return this.wasValid;
     }
@@ -200,7 +201,7 @@
         if (selectionList == null) {
             throw new IllegalArgumentException("An MultiValueField's selection list cannot
be null.");
         }
-        
+
         if (selectionList.getDatatype() != null &&
             selectionList.getDatatype() != definition.getDatatype()) {
 

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java?rev=231335&r1=231334&r2=231335&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java Wed Aug
10 14:40:35 2005
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,15 +40,23 @@
  *
  * <p>Using the methods {@link #getSize()} and {@link #getWidget(int, java.lang.String)}
  * you can access all of the repeated widget instances.
- * 
+ *
  * @version $Id$
  */
-public class Repeater extends AbstractWidget implements ValidationErrorAware //, ContainerWidget

-{
+public class Repeater extends AbstractWidget
+                      implements ValidationErrorAware {
+
+    private static final String REPEATER_EL = "repeater";
+    private static final String HEADINGS_EL = "headings";
+    private static final String HEADING_EL = "heading";
+    private static final String LABEL_EL = "label";
+    private static final String REPEATER_SIZE_EL = "repeater-size";
+
     private final RepeaterDefinition definition;
     private final List rows = new ArrayList();
     protected ValidationError validationError;
 
+
     public Repeater(RepeaterDefinition repeaterDefinition) {
         super(repeaterDefinition);
         this.definition = repeaterDefinition;
@@ -62,7 +70,7 @@
     public WidgetDefinition getDefinition() {
         return definition;
     }
-    
+
     public void initialize() {
         for (int i = 0; i < this.rows.size(); i++) {
             ((RepeaterRow)rows.get(i)).initialize();
@@ -81,7 +89,7 @@
         getForm().addWidgetUpdate(this);
         return repeaterRow;
     }
-    
+
     public RepeaterRow addRow(int index) {
         RepeaterRow repeaterRow = new RepeaterRow(definition);
         if (index >= this.rows.size()) {
@@ -97,30 +105,33 @@
     public RepeaterRow getRow(int index) {
         return (RepeaterRow)rows.get(index);
     }
-    
+
     /**
-     * Overrides {@link AbstractWidget#getChild(String)} to return the 
+     * Overrides {@link AbstractWidget#getChild(String)} to return the
      * repeater-row indicated by the index in 'id'
-     * 
+     *
      * @param id index of the row as a string-id
      * @return the repeater-row at the specified index
      */
     public Widget getChild(String id) {
-        int rowIndex = -1;
+        int rowIndex;
         try {
             rowIndex = Integer.parseInt(id);
         } catch (NumberFormatException nfe) {
             // Not a number
             return null;
         }
-        if (rowIndex < 0 || rowIndex >= getSize()) 
+
+        if (rowIndex < 0 || rowIndex >= getSize()) {
             return null;
+        }
+
         return getRow(rowIndex);
     }
-    
+
     /**
      * Crawls up the parents of a widget up to finding a repeater row.
-     * 
+     *
      * @param widget the widget whose row is to be found
      * @return the repeater row
      */
@@ -129,14 +140,14 @@
         while(result != null && ! (result instanceof Repeater.RepeaterRow)) {
             result = result.getParent();
         }
-        
+
         if (result == null) {
             throw new RuntimeException("Could not find a parent row for widget " + widget);
 
         }
         return (Repeater.RepeaterRow)result;
     }
-    
+
     /**
      * Get the position of a row in this repeater.
      * @param row the row which we search the index for
@@ -153,7 +164,7 @@
         rows.remove(index);
         getForm().addWidgetUpdate(this);
     }
-    
+
     public void moveRowLeft(int index) {
         if (index == 0 || index >= this.rows.size()) {
             // do nothing
@@ -175,7 +186,7 @@
         }
         getForm().addWidgetUpdate(this);
     }
-    
+
     /**
      * @deprecated {@see #clear()}
      *
@@ -184,13 +195,13 @@
         clear();
         getForm().addWidgetUpdate(this);
     }
-    
+
     /**
      * Clears all rows from the repeater and go back to the initial size
      */
     public void clear() {
         rows.clear();
-        
+
         // and reset to initial size
         for (int i = 0; i < this.definition.getInitialSize(); i++) {
             addRow();
@@ -208,7 +219,7 @@
         RepeaterRow row = (RepeaterRow)rows.get(rowIndex);
         return row.getChild(id);
     }
-    
+
     public void readFromRequest(FormContext formContext) {
         if (!getCombinedState().isAcceptingInputs())
             return;
@@ -256,33 +267,33 @@
             this.wasValid = true;
             return true;
         }
+
         boolean valid = true;
         Iterator rowIt = rows.iterator();
         while (rowIt.hasNext()) {
             RepeaterRow row = (RepeaterRow)rowIt.next();
             valid = valid & row.validate();
         }
-        this.wasValid = (valid ? super.validate() : false) && this.validationError
== null;
+
+        if (!valid) {
+            valid = super.validate();
+        }
+
+        this.wasValid = valid && this.validationError == null;
         return this.wasValid;
     }
 
 
-    private static final String REPEATER_EL = "repeater";
-    private static final String HEADINGS_EL = "headings";
-    private static final String HEADING_EL = "heading";
-    private static final String LABEL_EL = "label";
-    private static final String REPEATER_SIZE_EL = "repeater-size";
-    
 
     /**
      * @return "repeater"
      */
     public String getXMLElementName() {
         return REPEATER_EL;
-    }   
-    
-    
-    
+    }
+
+
+
 	/**
 	 * Adds @size attribute
 	 */
@@ -291,8 +302,8 @@
         attrs.addCDATAAttribute("size", String.valueOf(getSize()));
 		return attrs;
 	}
-    
-        
+
+
 	public void generateDisplayData(ContentHandler contentHandler)
 			throws SAXException {
         // the repeater's label
@@ -311,8 +322,8 @@
         }
         contentHandler.endElement(Constants.INSTANCE_NS, HEADINGS_EL, Constants.INSTANCE_PREFIX_COLON
+ HEADINGS_EL);
 	}
-    
-    
+
+
     public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws
SAXException {
         // the actual rows in the repeater
         Iterator rowIt = rows.iterator();
@@ -337,11 +348,11 @@
      * Generates a repeater-size element with a size attribute indicating the size of this
repeater.
      */
     public void generateSize(ContentHandler contentHandler) throws SAXException {
-        AttributesImpl attrs = getXMLElementAttributes(); 
+        AttributesImpl attrs = getXMLElementAttributes();
         contentHandler.startElement(Constants.INSTANCE_NS, REPEATER_SIZE_EL, Constants.INSTANCE_PREFIX_COLON
+ REPEATER_SIZE_EL, attrs);
         contentHandler.endElement(Constants.INSTANCE_NS, REPEATER_SIZE_EL, Constants.INSTANCE_PREFIX_COLON
+ REPEATER_SIZE_EL);
     }
-    
+
     /**
      * Set a validation error on this field. This allows repeaters be externally marked as
invalid by
      * application logic.
@@ -361,16 +372,14 @@
 
     public class RepeaterRow extends AbstractContainerWidget {
 
+        private static final String ROW_EL = "repeater-row";
+
         public RepeaterRow(RepeaterDefinition definition) {
             super(definition);
             setParent(Repeater.this);
-            ((ContainerDefinition)definition).createWidgets(this);
+            definition.createWidgets(this);
         }
 
-//        public String getLocation() {
-//            return Repeater.this.getLocation();
-//        }
-//        
         public WidgetDefinition getDefinition() {
             return Repeater.this.definition;
         }
@@ -402,7 +411,7 @@
         public Form getForm() {
             return Repeater.this.getForm();
         }
-        
+
         public void initialize() {
             // Initialize children but don't call super.initialize() that would call the
repeater's
             // on-create handlers for each row.
@@ -417,9 +426,6 @@
             // Validate only child widtgets, as the definition's validators are those of
the parent repeater
             return widgets.validate();
         }
-        
-        private static final String ROW_EL = "repeater-row";
-
 
         /**
          * @return "repeater-row"
@@ -430,16 +436,15 @@
 
         public void generateLabel(ContentHandler contentHandler) throws SAXException {
             // this widget has its label generated in the context of the repeater
-        }     
-        
+        }
+
         public void generateDisplayData(ContentHandler contentHandler)
                 throws SAXException {
             // this widget has its display-data generated in the context of the repeater
         }
-        
+
         public void broadcastEvent(WidgetEvent event) {
             throw new UnsupportedOperationException("Widget " + this.getRequestParameterName()
+ " doesn't handle events.");
         }
     }
-
 }



Mime
View raw message