cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jer...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel BooleanField.java BooleanFieldDefinitionBuilder.java
Date Fri, 02 Jul 2004 09:17:08 GMT
jeremy      2004/07/02 02:17:08

  Modified:    src/blocks/forms/java/org/apache/cocoon/forms/formmodel
                        BooleanField.java
                        BooleanFieldDefinitionBuilder.java
  Log:
  well, no one though anyone would need it, but we did ..... with Bruno's help, here is a
validatable BooleanField.
  
  Revision  Changes    Path
  1.11      +36 -3     cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
  
  Index: BooleanField.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BooleanField.java	7 May 2004 13:42:10 -0000	1.10
  +++ BooleanField.java	2 Jul 2004 09:17:08 -0000	1.11
  @@ -23,6 +23,10 @@
   import org.apache.cocoon.xml.XMLUtils;
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
  +import org.apache.cocoon.forms.validation.ValidationErrorAware;
  +import org.apache.cocoon.forms.validation.ValidationError;
  +
  +
   
   /**
    * A widget to select a boolean value. Usually rendered as a checkbox.
  @@ -37,13 +41,14 @@
    * 
    * @version $Id$
    */
  -public class BooleanField extends AbstractWidget implements ValueChangedListenerEnabled
{
  +public class BooleanField extends AbstractWidget implements ValidationErrorAware, ValueChangedListenerEnabled
{
       // FIXME(SW) : should the initial value be false or null ? This would allow
       // event listeners to be triggered at bind time.
       private Boolean value = Boolean.FALSE;
       private final BooleanFieldDefinition definition;
       /** Additional listeners to those defined as part of the widget definition (if any).
*/
       private ValueChangedListener listener;
  +    protected ValidationError validationError;
   
       public BooleanField(BooleanFieldDefinition definition) {
           this.definition = definition;
  @@ -54,6 +59,7 @@
       }
   
       public void readFromRequest(FormContext formContext) {
  +        validationError = null;
           Object oldValue = value;
           String param = formContext.getRequest().getParameter(getRequestParameterName());
           if (param != null && param.equalsIgnoreCase("true"))
  @@ -73,12 +79,33 @@
        */
       public boolean validate() {
           // a boolean field is always valid
  -        return true;
  +        //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.
  +     */
  +    public ValidationError getValidationError() {
  +        return validationError;
  +    }
  +
  +    /**
  +     * Set a validation error on this field. This allows fields to be externally marked
as invalid by
  +     * application logic.
  +     *
  +     * @param error the validation error
  +     */
  +    public void setValidationError(ValidationError error) {
  +        this.validationError = error;
       }
   
   
       private static final String BOOLEAN_FIELD_EL = "booleanfield";
       private static final String VALUE_EL = "value";
  +    private static final String VALIDATION_MSG_EL = "validation-message";
       
       /**
        * @return "booleanfield"
  @@ -93,6 +120,12 @@
           String stringValue = String.valueOf(value != null && value.booleanValue()
== true? "true": "false");
           contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length());
           contentHandler.endElement(Constants.INSTANCE_NS, VALUE_EL, Constants.INSTANCE_PREFIX_COLON
+ VALUE_EL);
  +        // validation message element: only present if the value is not valid
  +        if (validationError != null) {
  +            contentHandler.startElement(Constants.INSTANCE_NS, VALIDATION_MSG_EL, Constants.INSTANCE_PREFIX_COLON
+ VALIDATION_MSG_EL, XMLUtils.EMPTY_ATTRIBUTES);
  +            validationError.generateSaxFragment(contentHandler);
  +            contentHandler.endElement(Constants.INSTANCE_NS, VALIDATION_MSG_EL, Constants.INSTANCE_PREFIX_COLON
+ VALIDATION_MSG_EL);
  +        }
       }
   
       public Object getValue() {
  
  
  
  1.2       +2 -2      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java
  
  Index: BooleanFieldDefinitionBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BooleanFieldDefinitionBuilder.java	9 Mar 2004 10:33:49 -0000	1.1
  +++ BooleanFieldDefinitionBuilder.java	2 Jul 2004 09:17:08 -0000	1.2
  @@ -31,7 +31,7 @@
           setLocation(widgetElement, definition);
           setId(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());
  
  
  

Mime
View raw message