org.apache.cocoon.woody.formmodel
Class AggregateField

java.lang.Object
  extended by org.apache.cocoon.woody.formmodel.AbstractWidget
      extended by org.apache.cocoon.woody.formmodel.Field
          extended by org.apache.cocoon.woody.formmodel.AggregateField
All Implemented Interfaces:
DataWidget, SelectableWidget, Widget, ValidationErrorAware

public class AggregateField
extends Field

An aggregated field allows to represent one value as multiple input fields, or several values as one field. Hence this widget is a field and a container widget simultaneously.

Upon submit, it first attempts to read own value from the request, and splits over nested field widgets using a regular expression. If split fails, this will simply give a validation error. If own value was not submitted, it attempts to read values for nested field widgets, and combines theirs values using combine expression.

To validate this widget, both the validation rules of the nested widgets are checked, and those of the aggregated field themselves. The validation rules of the aggregated field can perform checks on the string as entered by the user (e.g. check its total length).

This field and nested fields can be of any supported type, as long as combine expression gives result of the correct type, and split regular expression can split string representation into parts which can be converted to the values of nested fields.

Version:
CVS $Id: AggregateField.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Field Summary
 
Fields inherited from class org.apache.cocoon.woody.formmodel.Field
enteredValue, needsParse, needsValidate, selectionList, validationError, value
 
Fields inherited from class org.apache.cocoon.woody.formmodel.AbstractWidget
definition
 
Constructor Summary
AggregateField(AggregateFieldDefinition definition)
           
 
Method Summary
protected  void addField(Field field)
           
 void combineFields()
           
 void generateLabel(ContentHandler contentHandler)
          Generates SAX events for the label of this widget.
 void generateSaxFragment(ContentHandler contentHandler, Locale locale)
          Generates an XML representation of this widget.
 AggregateFieldDefinition getAggregateFieldDefinition()
           
 Iterator getChildren()
           
 Widget getWidget(String id)
          Gets the child widget of this widget with the given id, or null if there isn't such a child.
 void readFromRequest(FormContext formContext)
          Lets this widget read its data from a request.
 void setValue(Object newValue)
          Sets the value of this widget to the given object.
 boolean validate(FormContext formContext)
          Validates this widget and returns the outcome.
 
Methods inherited from class org.apache.cocoon.woody.formmodel.Field
broadcastEvent, getDatatype, getFieldDefinition, getId, getValidationError, getValue, isRequired, readFromRequest, setSelectionList, setSelectionList, setSelectionList, setValidationError
 
Methods inherited from class org.apache.cocoon.woody.formmodel.AbstractWidget
addValidator, generateItemSaxFragment, generateSaxFragment, getForm, getFullyQualifiedId, getLocation, getNamespace, getParent, removeValidator, setDefinition, setLocation, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.woody.formmodel.Widget
getForm, getFullyQualifiedId, getLocation, getNamespace, getParent, setParent
 

Constructor Detail

AggregateField

public AggregateField(AggregateFieldDefinition definition)
Method Detail

getAggregateFieldDefinition

public final AggregateFieldDefinition getAggregateFieldDefinition()

addField

protected void addField(Field field)

getChildren

public Iterator getChildren()

readFromRequest

public void readFromRequest(FormContext formContext)
Description copied from interface: Widget
Lets this widget read its data from a request. At this point the Widget may try to convert the request parameter to its native datatype (if it is not a string), but it should not yet generate any validation errors.

Specified by:
readFromRequest in interface Widget
Overrides:
readFromRequest in class Field

setValue

public void setValue(Object newValue)
Description copied from interface: Widget
Sets the value of this widget to the given object. Some widgets may not support this method, those should throw an runtime exception if you try to set their value anyway.

Specified by:
setValue in interface Widget
Overrides:
setValue in class Field

combineFields

public void combineFields()

validate

public boolean validate(FormContext formContext)
Description copied from interface: Widget
Validates this widget and returns the outcome. Possible error messages are remembered by the widget itself and will be part of the XML produced by this widget in its Widget.generateSaxFragment(ContentHandler, Locale) method.

Specified by:
validate in interface Widget
Overrides:
validate in class Field

generateSaxFragment

public void generateSaxFragment(ContentHandler contentHandler,
                                Locale locale)
                         throws SAXException
Description copied from interface: Widget
Generates an XML representation of this widget. The startDocument and endDocument SAX events will not be called. It is assumed that the prefix for the Woody namespace mentioned in Constants.WI_PREFIX is already declared (by the caller or otherwise).

Specified by:
generateSaxFragment in interface Widget
Overrides:
generateSaxFragment in class Field
Throws:
SAXException

generateLabel

public void generateLabel(ContentHandler contentHandler)
                   throws SAXException
Description copied from interface: Widget
Generates SAX events for the label of this widget. The label will not be wrapped inside another element.

Specified by:
generateLabel in interface Widget
Overrides:
generateLabel in class Field
Throws:
SAXException

getWidget

public Widget getWidget(String id)
Description copied from interface: Widget
Gets the child widget of this widget with the given id, or null if there isn't such a child.

Specified by:
getWidget in interface Widget
Overrides:
getWidget in class AbstractWidget


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.