org.apache.cocoon.forms.formmodel
Class Union

java.lang.Object
  extended byorg.apache.cocoon.forms.formmodel.AbstractWidget
      extended byorg.apache.cocoon.forms.formmodel.AbstractContainerWidget
          extended byorg.apache.cocoon.forms.formmodel.Union
All Implemented Interfaces:
ContainerWidget, org.apache.cocoon.util.location.Locatable, Widget

public class Union
extends AbstractContainerWidget

A discriminated union that references a discriminant value in another widget and contains one of several cases (widgets). To have a case hold more than one widget or to use a different id for the case than for the widget id, just wrap the widget(s) in a container widget named with the desired case id.

Version:
$Id: Union.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  String caseValue
           
 
Fields inherited from class org.apache.cocoon.forms.formmodel.AbstractContainerWidget
validationError, widgets
 
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
Union(UnionDefinition definition)
           
 
Method Summary
 Widget getChild(String id)
          Gets the child widget with the given id.
 WidgetDefinition getDefinition()
          Get this widget's definition.
 Object getValue()
          Get the value of a 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.
 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)
          Delegates the readFromRequest() down to the contained child-widgets.
 boolean validate()
          Delegates the validate() down to the contained child-widgets, and validates the extra rules on this containment level regardless of children widget's validities.
 
Methods inherited from class org.apache.cocoon.forms.formmodel.AbstractContainerWidget
addChild, generateItemSaxFragment, getChildren, getSize, hasChild
 
Methods inherited from class org.apache.cocoon.forms.formmodel.AbstractWidget
addValidator, broadcastEvent, generateDisplayData, generateLabel, generateSaxFragment, getAttribute, getCombinedState, getForm, getFullName, getId, getLocation, getName, getParent, getRequestParameterName, getState, getWidget, getXMLElementAttributes, isRequired, isValid, lookupWidget, removeAttribute, removeValidator, setAttribute, setParent, setState, setValue, 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, broadcastEvent, generateLabel, generateSaxFragment, getAttribute, getCombinedState, getForm, getFullName, getId, getLocation, getName, getParent, getRequestParameterName, getState, getWidget, isRequired, isValid, lookupWidget, removeAttribute, removeValidator, setAttribute, setParent, setState, setValue
 

Field Detail

caseValue

protected String caseValue
Constructor Detail

Union

public Union(UnionDefinition definition)
Method Detail

getDefinition

public WidgetDefinition getDefinition()
Description copied from interface: Widget
Get this widget's definition.

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()
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 AbstractContainerWidget

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:
"field"

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

readFromRequest

public void readFromRequest(FormContext formContext)
Description copied from class: AbstractContainerWidget
Delegates the readFromRequest() down to the contained child-widgets. When overriding one should call super.readFromRequest() to allow child-widgets to process the request. Overide only to add possible request-reading statements on the containment level.

Specified by:
readFromRequest in interface Widget
Overrides:
readFromRequest in class AbstractContainerWidget
Parameters:
formContext - to be passed to the Widget.readFromRequest(FormContext) of the contained widgets.

validate

public boolean validate()
Description copied from class: AbstractContainerWidget
Delegates the validate() down to the contained child-widgets, and validates the extra rules on this containment level regardless of children widget's validities.

When overriding one should call super.validate() as the first statement to keep in sync with this behaviour.

Specified by:
validate in interface Widget
Overrides:
validate in class AbstractContainerWidget
Returns:
true only if all contained widgets are valid and the extra validation rules on this containment level are ok.

getChild

public Widget getChild(String id)
Description copied from interface: ContainerWidget
Gets the child widget with the given id.

Specified by:
getChild in interface ContainerWidget
Overrides:
getChild in class AbstractContainerWidget


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.