org.apache.cocoon.woody.formmodel
Class MultiValueField

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

public class MultiValueField
extends AbstractWidget
implements ValidationErrorAware, SelectableWidget

A MultiValueField is mostly the same as a normal Field, but can hold multiple values. A MultiValueField should have a Datatype which has a SelectionList, because the user will always select the values from a list. A MultiValueField has no concept of "required", you should instead use the ValueCountValidationRule to check how many items the user has selected.

A MultiValueField also has a Datatype associated with it. In case of MultiValueFields, this Datatype will always be an array type, thus Datatype.isArrayType() will always return true, and this in return has an influence on the kind of validation rules that can be used with the Datatype (see Datatype description for more information).

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

Field Summary
 
Fields inherited from class org.apache.cocoon.woody.formmodel.AbstractWidget
definition
 
Constructor Summary
MultiValueField(MultiValueFieldDefinition definition)
           
 
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.
 String getId()
          Gets the id of this widget.
 ValidationError getValidationError()
           
 Object getValue()
          Returns the value of the widget.
 void readFromRequest(FormContext formContext)
          Lets this widget read its data from a request.
 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)
           
 void setValue(Object value)
          Sets the value of this widget to the given object.
 void setValues(Object[] values)
           
 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, isRequired, 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, isRequired, setParent
 

Constructor Detail

MultiValueField

public MultiValueField(MultiValueFieldDefinition definition)
Method Detail

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

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

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

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

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 value)
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

setValues

public void setValues(Object[] values)

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.

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

getValidationError

public ValidationError getValidationError()
Specified by:
getValidationError in interface ValidationErrorAware

setValidationError

public void setValidationError(ValidationError error)
Specified by:
setValidationError in interface ValidationErrorAware


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