org.apache.cocoon.woody.formmodel
Class Field

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

public class Field
extends AbstractWidget
implements ValidationErrorAware, DataWidget, SelectableWidget

A general-purpose Widget that can hold one value. A Field widget can be associated with a Datatype, and thus a Field widget can be used to edit different kinds of data, such as strings, numbers and dates. A Datatype can also have an associated SelectionList, so that the value for the Field can be selected from a list, rather than being entered in a textbox. The validation of the field is delegated to its associated Datatype.

Version:
CVS $Id: Field.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Bruno Dumon, Sylvain Wallez

Field Summary
protected  String enteredValue
           
protected  boolean needsParse
           
protected  boolean needsValidate
           
protected  SelectionList selectionList
           
protected  ValidationError validationError
           
protected  Object value
           
 
Fields inherited from class org.apache.cocoon.woody.formmodel.AbstractWidget
definition
 
Constructor Summary
Field(FieldDefinition fieldDefinition)
           
 
Method Summary
 void broadcastEvent(WidgetEvent event)
          Broadcast an event previously queued by this widget to its event listeners.
 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.
 Datatype getDatatype()
           
 FieldDefinition getFieldDefinition()
           
 String getId()
          Gets the id of this widget.
 ValidationError getValidationError()
          Returns the validation error, if any.
 Object getValue()
          Returns the value of the widget.
 boolean isRequired()
          Returns wether this widget is required to be filled in.
 void readFromRequest(FormContext formContext)
          Lets this widget read its data from a request.
protected  void readFromRequest(String newEnteredValue)
           
 void setSelectionList(Object model, String valuePath, String labelPath)
          Set this field's selection list using values from an in-memory object.
 void setSelectionList(SelectionList selectionList)
          Set this field's selection list.
 void setSelectionList(String uri)
          Read this field's selection list from an external source.
 void setValidationError(ValidationError error)
          Set a validation error on this field.
 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.AbstractWidget
addValidator, generateItemSaxFragment, generateSaxFragment, getForm, getFullyQualifiedId, getLocation, getNamespace, getParent, getWidget, 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, getWidget, setParent
 

Field Detail

selectionList

protected SelectionList selectionList

enteredValue

protected String enteredValue

value

protected Object value

needsParse

protected boolean needsParse

needsValidate

protected boolean needsValidate

validationError

protected ValidationError validationError
Constructor Detail

Field

public Field(FieldDefinition fieldDefinition)
Method Detail

getFieldDefinition

public final FieldDefinition getFieldDefinition()

getId

public String getId()
Description copied from class: AbstractWidget
Gets the id of this widget.

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

getValue

public Object getValue()
Description copied from interface: Widget
Returns the value of the widget. For some widgets (notably ContainerWidgets) this may not make sense, those should then simply return null here.

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

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 AbstractWidget

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

readFromRequest

protected void readFromRequest(String newEnteredValue)

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 AbstractWidget

getValidationError

public ValidationError getValidationError()
Returns the validation error, if any. There will always be a validation error in case the validate(FormContext) method returned false.

Specified by:
getValidationError in interface ValidationErrorAware

setValidationError

public void setValidationError(ValidationError error)
Set a validation error on this field. This allows fields to be externally marked as invalid by application logic.

Specified by:
setValidationError in interface ValidationErrorAware
Parameters:
error - the validation error

isRequired

public boolean isRequired()
Description copied from interface: Widget
Returns wether this widget is required to be filled in. As with Widget.getValue(), for some widgets this may not make sense, those should return false here.

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

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
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 AbstractWidget
Throws:
SAXException

setSelectionList

public void setSelectionList(SelectionList selectionList)
Set this field's selection list.

Specified by:
setSelectionList in interface SelectableWidget
Parameters:
selectionList - The new selection list.

setSelectionList

public void setSelectionList(String uri)
Read this field's selection list from an external source. All Cocoon-supported protocols can be used. The format of the XML produced by the source should be the same as in case of inline specification of the selection list, thus the root element should be a wd:selection-list element.

Specified by:
setSelectionList in interface SelectableWidget
Parameters:
uri - The URI of the source.

setSelectionList

public void setSelectionList(Object model,
                             String valuePath,
                             String labelPath)
Set this field's selection list using values from an in-memory object. The object parameter should point to a collection (Java collection or array, or Javascript array) of objects. Each object belonging to the collection should have a value property and a label property, whose values are used to specify the value attribute and the contents of the wd:label child element of every wd:item in the list.

Access to the values of the above mentioned properties is done via XPath expressions.

Specified by:
setSelectionList in interface SelectableWidget
Parameters:
model - The collection used as a model for the selection list.
valuePath - An XPath expression referring to the attribute used to populate the values of the list's items.
labelPath - An XPath expression referring to the attribute used to populate the labels of the list's items.

getDatatype

public Datatype getDatatype()
Specified by:
getDatatype in interface DataWidget

broadcastEvent

public void broadcastEvent(WidgetEvent event)
Description copied from interface: Widget
Broadcast an event previously queued by this widget to its event listeners.

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


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