org.apache.cocoon.forms.formmodel
Class Repeater

java.lang.Object
  extended byorg.apache.cocoon.forms.formmodel.AbstractWidget
      extended byorg.apache.cocoon.forms.formmodel.Repeater
All Implemented Interfaces:
org.apache.cocoon.util.location.Locatable, ValidationErrorAware, Widget
Direct Known Subclasses:
EnhancedRepeater

public class Repeater
extends AbstractWidget
implements ValidationErrorAware

A repeater is a widget that repeats a number of other widgets.

Technically, the Repeater widget is a ContainerWidget whose children are Repeater.RepeaterRows, and the RepeaterRows in turn are ContainerWidgets containing the actual repeated widgets. However, in practice, you won't need to use the RepeaterRow widget directly.

Using the methods getSize() and getWidget(int, java.lang.String) you can access all of the repeated widget instances.

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

Nested Class Summary
 class Repeater.RepeaterRow
           
 
Field Summary
protected  RepeaterDefinition definition
           
protected  List rows
           
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
Repeater(RepeaterDefinition repeaterDefinition)
           
 
Method Summary
 void addRepeaterListener(RepeaterListener listener)
           
 Repeater.RepeaterRow addRow()
           
 Repeater.RepeaterRow addRow(int index)
           
 void broadcastEvent(WidgetEvent event)
          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. Abstract implementation throws a UnsupportedOperationException.
 void clear()
          Clears all rows from the repeater and go back to the initial size
 void generateDisplayData(ContentHandler contentHandler)
          Delegates to the getDefinition() of this widget to generate a common set of 'display' data.
 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.
 void generateSize(ContentHandler contentHandler)
          Generates a repeater-size element with a size attribute indicating the size of this repeater.
 void generateWidgetLabel(String widgetId, ContentHandler contentHandler)
          Generates the label of a certain widget in this repeater.
 Widget getChild(String id)
          Overrides AbstractWidget.getChild(String) to return the repeater-row indicated by the index in 'id'
 WidgetDefinition getDefinition()
          Concrete subclasses should allow access to their underlaying Definition through this method.
 int getMaxSize()
           
 int getMinSize()
           
static Repeater.RepeaterRow getParentRow(Widget widget)
          Crawls up the parents of a widget up to finding a repeater row.
 Repeater.RepeaterRow getRow(int index)
           
 int getSize()
           
 ValidationError getValidationError()
          Set a validation error on this field.
 Widget getWidget(int rowIndex, String id)
          Gets a widget on a certain row.
 org.apache.cocoon.xml.AttributesImpl getXMLElementAttributes()
          Adds @size 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 hasRepeaterListeners()
           
 int indexOf(Repeater.RepeaterRow row)
          Get the position of a row in this repeater.
 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 moveRow(int from, int to)
          Move a row from one place to another
 void moveRow2(int from, int to)
          Move a row from one place to another.
 void moveRowLeft(int index)
           
 void moveRowRight(int index)
           
 void readFromRequest(FormContext formContext)
          Lets this widget read its data from a request.
 void removeRepeaterListener(RepeaterListener listener)
           
 void removeRow(int index)
           
 void removeRows()
          Deprecated. See clear()
 void setValidationError(ValidationError error)
          set a validation error
 boolean validate()
          Validates this widget and returns the outcome.
 
Methods inherited from class org.apache.cocoon.forms.formmodel.AbstractWidget
addValidator, generateLabel, generateSaxFragment, getAttribute, getCombinedState, getForm, getFullName, getId, getLocation, getName, getParent, getRequestParameterName, getState, getValue, getWidget, 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
 

Field Detail

definition

protected final RepeaterDefinition definition

rows

protected final List rows

validationError

protected ValidationError validationError
Constructor Detail

Repeater

public Repeater(RepeaterDefinition repeaterDefinition)
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

getSize

public int getSize()

getMinSize

public int getMinSize()

getMaxSize

public int getMaxSize()

addRow

public Repeater.RepeaterRow addRow()

addRow

public Repeater.RepeaterRow addRow(int index)

getRow

public Repeater.RepeaterRow getRow(int index)

getChild

public Widget getChild(String id)
Overrides AbstractWidget.getChild(String) to return the repeater-row indicated by the index in 'id'

Overrides:
getChild in class AbstractWidget
Parameters:
id - index of the row as a string-id
Returns:
the repeater-row at the specified index

getParentRow

public static Repeater.RepeaterRow getParentRow(Widget widget)
Crawls up the parents of a widget up to finding a repeater row.

Parameters:
widget - the widget whose row is to be found
Returns:
the repeater row

indexOf

public int indexOf(Repeater.RepeaterRow row)
Get the position of a row in this repeater.

Parameters:
row - the row which we search the index for
Returns:
the row position or -1 if this row is not in this repeater

removeRow

public void removeRow(int index)
Throws:
IndexOutOfBoundsException - if the the index is outside the range of existing rows.

moveRow

public void moveRow(int from,
                    int to)
Move a row from one place to another

Parameters:
from - the existing row position
to - the target position. The "from" item will be moved before that position.

moveRow2

public void moveRow2(int from,
                     int to)
Move a row from one place to another. In contrast to moveRow(int, int), this method treats the to-index as the exact row-index where you want to have the row moved to.

Parameters:
from - the existing row position
to - the target position. The "from" item will be moved before that position.

moveRowLeft

public void moveRowLeft(int index)

moveRowRight

public void moveRowRight(int index)

removeRows

public void removeRows()
Deprecated. See clear()


clear

public void clear()
Clears all rows from the repeater and go back to the initial size


addRepeaterListener

public void addRepeaterListener(RepeaterListener listener)

removeRepeaterListener

public void removeRepeaterListener(RepeaterListener listener)

hasRepeaterListeners

public boolean hasRepeaterListeners()

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

getWidget

public Widget getWidget(int rowIndex,
                        String id)
Gets a widget on a certain row.

Parameters:
rowIndex - startin from 0
id - a widget id
Returns:
null if there's no such widget

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

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

getXMLElementAttributes

public org.apache.cocoon.xml.AttributesImpl getXMLElementAttributes()
Adds @size attribute

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

generateDisplayData

public void generateDisplayData(ContentHandler contentHandler)
                         throws SAXException
Description copied from class: AbstractWidget
Delegates to the AbstractWidget.getDefinition() of this widget to generate a common set of 'display' data. (i.e. help, label, hint,...) Subclasses should override if the getDefinition can return null to avoid NPE's.

Overrides:
generateDisplayData in class AbstractWidget
Parameters:
contentHandler - where to send the SAX events to.
Throws:
SAXException
See Also:
WidgetDefinition.generateDisplayData(ContentHandler)

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

generateWidgetLabel

public void generateWidgetLabel(String widgetId,
                                ContentHandler contentHandler)
                         throws SAXException
Generates the label of a certain widget in this repeater.

Throws:
SAXException

generateSize

public void generateSize(ContentHandler contentHandler)
                  throws SAXException
Generates a repeater-size element with a size attribute indicating the size of this repeater.

Throws:
SAXException

getValidationError

public ValidationError getValidationError()
Set a validation error on this field. This allows repeaters be externally marked as invalid by application logic.

Specified by:
getValidationError in interface ValidationErrorAware
Returns:
the validation error

setValidationError

public void setValidationError(ValidationError error)
set a validation error

Specified by:
setValidationError in interface ValidationErrorAware


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