org.apache.cocoon.forms.formmodel
Class Union

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

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 1304258 2012-03-23 10:09:27Z 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)
          Concrete widgets that contain actual child widgets should override to return the actual child-widget.
 WidgetDefinition getDefinition()
          Concrete subclasses should allow access to their underlaying Definition through this method.
 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 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()
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
Returns:
the value of the widget.

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.
See Also:
Widget.validate()

getChild

public Widget getChild(String id)
Description copied from class: AbstractWidget
Concrete widgets that contain actual child widgets should override to return the actual child-widget.

Specified by:
getChild in interface ContainerWidget
Overrides:
getChild in class AbstractContainerWidget
Parameters:
id - of the child-widget
Returns:
null if not overriden.


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