org.apache.cocoon.forms.formmodel
Class BooleanField

java.lang.Object
  extended by org.apache.cocoon.forms.formmodel.AbstractWidget
      extended by org.apache.cocoon.forms.formmodel.BooleanField
All Implemented Interfaces:
ValueChangedListenerEnabled, Widget, ValidationErrorAware, Locatable

public class BooleanField
extends AbstractWidget
implements ValidationErrorAware, ValueChangedListenerEnabled

A widget to select a boolean value. Usually rendered as a checkbox.

You may wonder why we don't use a Field widget with an associated Boolean Datatype instead. The reason is that many of the features of the Field widget are overkill for a Boolean: validation is unnecessary (if the field is not true it is false), the selectionlist associated with a Datatype also has no purpose here (there would always be only 2 choices: true or false), and the manner in which the request parameter of this widget is interpreted is different (missing or empty request parameter means 'false', rather than null value).

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

Field Summary
protected  ValidationError validationError
           
 
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
BooleanField(BooleanFieldDefinition definition)
           
 
Method Summary
 void addValueChangedListener(ValueChangedListener listener)
          Adds a ValueChangedListener to this widget instance.
 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.
 WidgetDefinition getDefinition()
          Concrete subclasses should allow access to their underlaying Definition through this method.
 ValidationError getValidationError()
          Returns the validation error, if any.
 Object getValue()
          Get the value of a widget.
protected  AttributesImpl getXMLElementAttributes()
          The XML attributes used in AbstractWidget.generateSaxFragment(ContentHandler, Locale) to be placed on the wrapping element for all the XML-instance-content of this Widget.
 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.
 void readFromRequest(FormContext formContext)
          Lets this widget read its data from a request.
 void removeValueChangedListener(ValueChangedListener listener)
           
 void setValidationError(ValidationError error)
          Set a validation error on this field.
 void setValue(Object object)
          Sets value of the field.
 
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, isRequired, isValid, lookupWidget, removeAttribute, removeValidator, setAttribute, setParent, setState, toString, validate, widgetNameChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

validationError

protected ValidationError validationError
Constructor Detail

BooleanField

public BooleanField(BooleanFieldDefinition definition)
Method Detail

getDefinition

public WidgetDefinition getDefinition()
Description copied from class: AbstractWidget
Concrete subclasses should allow access to their underlaying Definition through this method. If subclasses decide to return 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.

Specified by:
getDefinition in interface Widget
Specified by:
getDefinition in class AbstractWidget
Returns:
the widgetDefinition from which this widget was instantiated. (See WidgetDefinition.createInstance())

initialize

public void initialize()
Description copied from class: AbstractWidget
Called after widget's environment has been setup, to allow for any contextual initalization, such as looking up case widgets for union widgets.

Specified by:
initialize in interface Widget
Overrides:
initialize 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

getValidationError

public ValidationError getValidationError()
Returns the validation error, if any. There will always be a validation error in case the AbstractWidget.validate() 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

getXMLElementName

public String getXMLElementName()
Description copied from class: AbstractWidget
The XML element name used in AbstractWidget.generateSaxFragment(ContentHandler, Locale) to produce the wrapping element for all the XML-instance-content of this Widget.

Specified by:
getXMLElementName in class AbstractWidget
Returns:
"booleanfield"

getXMLElementAttributes

protected AttributesImpl getXMLElementAttributes()
Description copied from class: AbstractWidget
The XML attributes used in AbstractWidget.generateSaxFragment(ContentHandler, Locale) to be placed on the wrapping element for all the XML-instance-content of this Widget. This automatically adds @id=AbstractWidget.getRequestParameterName() to that element. Concrete subclasses should call super.getXMLElementAttributes and possibly add additional attributes. Note: the @id is not added for those widgets who's getId() returns null (e.g. top-level container widgets like 'form'). The contract of returning a non-null AttributesImpl is however maintained.

Overrides:
getXMLElementAttributes in class AbstractWidget
Returns:
the attributes for the main element for this widget's sax-fragment.

generateItemSaxFragment

public void generateItemSaxFragment(ContentHandler contentHandler,
                                    Locale locale)
                             throws SAXException
Description copied from class: AbstractWidget
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. Subclasses need to override to insert widget specific content.

Overrides:
generateItemSaxFragment in class AbstractWidget
Parameters:
contentHandler - to send the SAX events to
locale - in which context potential content needs to be put.
Throws:
SAXException

getValue

public Object getValue()
Description copied from interface: Widget
Get the value of a widget.

Not all widgets do have a value (notably ContainerWidgets, but this method is provided here as a convenience to ease writing and avoiding casts.

Specified by:
getValue in interface Widget
Overrides:
getValue in class AbstractWidget
Returns:
the value of the widget.

setValue

public void setValue(Object object)
Sets value of the field. If value is null, it is considered to be false (see class comment).

Specified by:
setValue in interface Widget
Overrides:
setValue in class AbstractWidget
Parameters:
object - the new widget's value.

addValueChangedListener

public void addValueChangedListener(ValueChangedListener listener)
Adds a ValueChangedListener to this widget instance. Listeners defined on the widget instance will be executed in addtion to any listeners that might have been defined in the widget definition.

Specified by:
addValueChangedListener in interface ValueChangedListenerEnabled

removeValueChangedListener

public void removeValueChangedListener(ValueChangedListener listener)
Specified by:
removeValueChangedListener in interface ValueChangedListenerEnabled

hasValueChangedListeners

public boolean hasValueChangedListeners()
Specified by:
hasValueChangedListeners in interface ValueChangedListenerEnabled

broadcastEvent

public void broadcastEvent(WidgetEvent event)
Description copied from class: AbstractWidget
Broadcast an event previously queued by this widget to its event listeners. Abstract implementation throws a UnsupportedOperationException. Concrete subclass widgets need to override when supporting event broadcasting.

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


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