|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.cocoon.forms.formmodel.AbstractWidget org.apache.cocoon.forms.formmodel.Field
public class Field
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.
Field Summary | |
---|---|
protected String |
enteredValue
|
protected boolean |
required
|
protected SelectionList |
selectionList
Overrides selection list defined in FieldDefinition, if any. |
static String |
SUGGESTED_LABEL_ATTR
If the field was rendered as a suggestion-list and the user chose one of the suggestions, the field's value is the chosen item's value and the SUGGESTED_LABEL_ATTR field
attribute contains the chosen item's label. |
protected SelectionList |
suggestionList
Overrides sugestion list defined in FieldDefinition, if any. |
protected ValidationError |
validationError
|
protected Object |
value
|
protected static int |
VALUE_DISPLAY_PARSE_ERROR
Value state indicating that validate() has been called when state was VALUE_PARSE_ERROR. |
protected static int |
VALUE_DISPLAY_VALIDATION
Value state indicating that value validation has occured, and the validation error, if any, should be displayed. |
protected static int |
VALUE_PARSE_ERROR
Value state indicating that a parse error was encountered but should not yet be displayed. |
protected static int |
VALUE_PARSED
Value state indicating that a value has been parsed, but needs to be validated (that must occur before the value is given to the application) |
protected static int |
VALUE_UNPARSED
Value state indicating that a new value has been read from the request, but has not yet been parsed. |
protected static int |
VALUE_VALIDATED
Value state indicating that validation has occured, but that any error should not yet be displayed. |
protected static int |
VALUE_VALIDATING
Transient value state indicating that validation is going on. |
protected int |
valueState
Transient widget processing state indicating that the widget is currently validating (used to avoid endless loops when a validator calls getValue). |
Fields inherited from class org.apache.cocoon.forms.formmodel.AbstractWidget |
---|
wasValid |
Fields inherited from interface org.apache.cocoon.forms.formmodel.Widget |
---|
PATH_SEPARATOR |
Constructor Summary | |
---|---|
Field(FieldDefinition fieldDefinition)
|
Method Summary | |
---|---|
void |
addValueChangedListener(ValueChangedListener listener)
Adds a ValueChangedListener to this widget instance. |
protected String |
applyWhitespaceTrim(String value)
|
void |
broadcastEvent(WidgetEvent event)
Broadcast an event previously queued by this widget to its event listeners. |
void |
generateItemSaxFragment(ContentHandler contentHandler,
Locale locale)
Generates nested additional content nested inside the main element for this widget which is generated by AbstractWidget.generateSaxFragment(ContentHandler, Locale)
The implementation on the AbstractWidget level inserts no additional XML. |
Datatype |
getDatatype()
|
WidgetDefinition |
getDefinition()
Concrete subclasses should allow access to their underlaying Definition through this method. |
FieldDefinition |
getFieldDefinition()
|
String |
getSuggestionLabel()
If the user has chosen an item in a suggestion list, returns that item's label. |
SelectionList |
getSuggestionList()
|
ValidationError |
getValidationError()
Returns the validation error, if any. |
Object |
getValue()
Get the value of a widget. |
AttributesImpl |
getXMLElementAttributes()
Adds the @required attribute |
String |
getXMLElementName()
The XML element name used in AbstractWidget.generateSaxFragment(ContentHandler, Locale)
to produce the wrapping element for all the XML-instance-content of this Widget. |
boolean |
hasValueChangedListeners()
|
void |
initialize()
Called after widget's environment has been setup, to allow for any contextual initalization, such as looking up case widgets for union widgets. |
boolean |
isRequired()
|
boolean |
isSuggested()
If this field has a selection-list, indicates if the value comes from that list or if a new value was input by the user. |
void |
readFromRequest(FormContext formContext)
Lets this widget read its data from a request. |
protected void |
readFromRequest(String newEnteredValue)
|
void |
removeValueChangedListener(ValueChangedListener listener)
|
void |
setRequired(boolean required)
|
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 |
setSuggestionLabel(String label)
Set the suggestion label associated to the widget's current value. |
void |
setSuggestionList(SelectionList suggestionList)
Set this field's suggestion list. |
void |
setSuggestionList(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. |
boolean |
validate()
Validates this widget and returns the outcome. |
Methods inherited from class org.apache.cocoon.forms.formmodel.AbstractWidget |
---|
addValidator, generateDisplayData, generateLabel, generateSaxFragment, getAttribute, getChild, getCombinedState, getForm, getFullName, getId, getLocation, getName, getParent, getRequestParameterName, getState, getWidget, isValid, lookupWidget, removeAttribute, removeValidator, setAttribute, setParent, setState, toString, widgetNameChanged |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.apache.cocoon.forms.formmodel.Widget |
---|
addValidator, generateLabel, generateSaxFragment, getAttribute, getCombinedState, getForm, getFullName, getId, getLocation, getName, getParent, getRequestParameterName, getState, getWidget, isValid, lookupWidget, removeAttribute, removeValidator, setAttribute, setParent, setState |
Field Detail |
---|
public static final String SUGGESTED_LABEL_ATTR
SUGGESTED_LABEL_ATTR
field
attribute contains the chosen item's label.
isSuggested()
,
Constant Field Valuesprotected static final int VALUE_UNPARSED
protected static final int VALUE_PARSED
protected static final int VALUE_PARSE_ERROR
protected static final int VALUE_DISPLAY_PARSE_ERROR
protected static final int VALUE_VALIDATING
validate()
,
Constant Field Valuesprotected static final int VALUE_VALIDATED
protected static final int VALUE_DISPLAY_VALIDATION
protected SelectionList selectionList
protected SelectionList suggestionList
protected String enteredValue
protected Object value
protected boolean required
protected int valueState
protected ValidationError validationError
Constructor Detail |
---|
public Field(FieldDefinition fieldDefinition)
Method Detail |
---|
public WidgetDefinition getDefinition()
AbstractWidget
null
they should also organize
own implementations of AbstractWidget.getId()
, AbstractWidget.getLocation()
,
AbstractWidget.validate()
, AbstractWidget.generateLabel(ContentHandler)
and
AbstractWidget.generateDisplayData(ContentHandler)
to avoid NPE's.
getDefinition
in interface Widget
getDefinition
in class AbstractWidget
WidgetDefinition.createInstance()
)public final FieldDefinition getFieldDefinition()
public void initialize()
AbstractWidget
initialize
in interface Widget
initialize
in class AbstractWidget
public boolean isSuggested()
public void setSuggestionLabel(String label)
public String getSuggestionLabel()
null
if the user entered a new value or
if there's not suggestion list.public Object getValue()
Widget
Not all widgets do have a value (notably ContainerWidget
s,
but this method is provided here as a convenience to ease writing and avoiding casts.
getValue
in interface Widget
getValue
in class AbstractWidget
public void setValue(Object newValue)
Widget
Not all widgets do have a value (notably ContainerWidget
s,
but this method is provided here as a convenience to ease writing and avoiding casts.
setValue
in interface Widget
setValue
in class AbstractWidget
newValue
- the new widget's value.public void readFromRequest(FormContext formContext)
Widget
readFromRequest
in interface Widget
protected void readFromRequest(String newEnteredValue)
protected String applyWhitespaceTrim(String value)
public boolean validate()
Widget
Widget.generateSaxFragment(ContentHandler, Locale)
method.
validate
in interface Widget
validate
in class AbstractWidget
true
to indicate all validations were ok,
false
otherwiseWidget.validate()
public ValidationError getValidationError()
validate()
method returned false.
getValue()
if value
is not parsed yet.
getValidationError
in interface ValidationErrorAware
public void setValidationError(ValidationError error)
setValidationError
in interface ValidationErrorAware
error
- the validation errorpublic boolean isRequired()
isRequired
in interface Widget
isRequired
in class AbstractWidget
Widget.getValue()
,
for some widgets this may not make sense, those should return false here.public void setRequired(boolean required)
public String getXMLElementName()
AbstractWidget
AbstractWidget.generateSaxFragment(ContentHandler, Locale)
to produce the wrapping element for all the XML-instance-content of this Widget.
getXMLElementName
in class AbstractWidget
public AttributesImpl getXMLElementAttributes()
getXMLElementAttributes
in class AbstractWidget
public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException
AbstractWidget
AbstractWidget.generateSaxFragment(ContentHandler, Locale)
The implementation on the AbstractWidget level inserts no additional XML.
Subclasses need to override to insert widget specific content.
generateItemSaxFragment
in class AbstractWidget
contentHandler
- to send the SAX events tolocale
- in which context potential content needs to be put.
SAXException
public void setSelectionList(SelectionList selectionList)
setSelectionList
in interface SelectableWidget
selectionList
- The new selection list.public void setSuggestionList(SelectionList suggestionList)
suggestionList
- The new suggestion list.public void setSelectionList(String uri)
fd:selection-list
element.
setSelectionList
in interface SelectableWidget
uri
- The URI of the source.public void setSelectionList(Object model, String valuePath, String labelPath)
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 fd:label
child element
of every fd:item
in the list.
Access to the values of the above mentioned properties is done via XPath expressions.
setSelectionList
in interface SelectableWidget
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.public void setSuggestionList(String uri)
fd:selection-list
element.
uri
- The URI of the source.public SelectionList getSuggestionList()
public Datatype getDatatype()
getDatatype
in interface DataWidget
public void addValueChangedListener(ValueChangedListener listener)
addValueChangedListener
in interface ValueChangedListenerEnabled
public void removeValueChangedListener(ValueChangedListener listener)
removeValueChangedListener
in interface ValueChangedListenerEnabled
public boolean hasValueChangedListeners()
hasValueChangedListeners
in interface ValueChangedListenerEnabled
public void broadcastEvent(WidgetEvent event)
AbstractWidget
UnsupportedOperationException
.
Concrete subclass widgets need to override when supporting event broadcasting.
broadcastEvent
in interface Widget
broadcastEvent
in class AbstractWidget
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |