org.apache.cocoon.woody.formmodel
Class Repeater

java.lang.Object
  extended by org.apache.cocoon.woody.formmodel.AbstractWidget
      extended by org.apache.cocoon.woody.formmodel.Repeater
All Implemented Interfaces:
ContainerWidget, Widget

public class Repeater
extends AbstractWidget
implements ContainerWidget

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 1304258 2012-03-23 10:09:27Z ilgrosso $

Nested Class Summary
 class Repeater.RepeaterRow
           
 
Field Summary
 
Fields inherited from class org.apache.cocoon.woody.formmodel.AbstractWidget
definition
 
Constructor Summary
Repeater(RepeaterDefinition repeaterDefinition)
           
 
Method Summary
 Repeater.RepeaterRow addRow()
           
 Repeater.RepeaterRow addRow(int index)
           
 void addWidget(Widget widget)
          Adds a child widget.
 void generateLabel(ContentHandler contentHandler)
          Generates SAX events for the label of this widget.
 void generateSaxFragment(ContentHandler contentHandler, Locale locale)
          Generates an XML representation of this widget.
 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.
 Iterator getChildren()
          Returns an iterator over the widgets this object contains
 String getId()
          Gets the id of this widget.
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()
           
 Widget getWidget(int rowIndex, String id)
          Gets a widget on a certain row.
 Widget getWidget(String id)
          Gets the child widget of this widget with the given id, or null if there isn't such a child.
 boolean hasWidget(String id)
          Checks if there is a child widget with the given id.
 int indexOf(Repeater.RepeaterRow row)
          Get the position of a row in this repeater.
 void moveRowLeft(int index)
           
 void moveRowRight(int index)
           
 void readFromRequest(FormContext formContext)
          Lets this widget read its data from a request.
 void removeRow(int index)
           
 void removeRows()
          Clears all rows from the repeater and go back to the initial size
 boolean validate(FormContext formContext)
          Validates this widget and returns the outcome.
 
Methods inherited from class org.apache.cocoon.woody.formmodel.AbstractWidget
addValidator, broadcastEvent, generateItemSaxFragment, generateSaxFragment, getForm, getFullyQualifiedId, getLocation, getNamespace, getParent, getValue, isRequired, removeValidator, setDefinition, setLocation, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.woody.formmodel.Widget
broadcastEvent, getForm, getFullyQualifiedId, getLocation, getNamespace, getParent, getValue, isRequired, setParent, setValue
 

Constructor Detail

Repeater

public Repeater(RepeaterDefinition repeaterDefinition)
Method Detail

getId

public String getId()
Description copied from class: AbstractWidget
Gets the id of this widget.

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

getSize

public int getSize()

addWidget

public void addWidget(Widget widget)
Description copied from interface: ContainerWidget
Adds a child widget.

Specified by:
addWidget in interface ContainerWidget

addRow

public Repeater.RepeaterRow addRow()

addRow

public Repeater.RepeaterRow addRow(int index)

getRow

public Repeater.RepeaterRow getRow(int 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.

moveRowLeft

public void moveRowLeft(int index)

moveRowRight

public void moveRowRight(int index)

removeRows

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


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

hasWidget

public boolean hasWidget(String id)
Description copied from interface: ContainerWidget
Checks if there is a child widget with the given id.

Specified by:
hasWidget in interface ContainerWidget

getWidget

public Widget getWidget(String id)
Description copied from interface: Widget
Gets the child widget of this widget with the given id, or null if there isn't such a child.

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

validate

public boolean validate(FormContext formContext)
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

generateSaxFragment

public void generateSaxFragment(ContentHandler contentHandler,
                                Locale locale)
                         throws SAXException
Description copied from interface: Widget
Generates an XML representation of this widget. The startDocument and endDocument SAX events will not be called. It is assumed that the prefix for the Woody namespace mentioned in Constants.WI_PREFIX is already declared (by the caller or otherwise).

Specified by:
generateSaxFragment in interface Widget
Throws:
SAXException

generateLabel

public void generateLabel(ContentHandler contentHandler)
                   throws SAXException
Description copied from interface: Widget
Generates SAX events for the label of this widget. The label will not be wrapped inside another element.

Specified by:
generateLabel in interface Widget
Overrides:
generateLabel in class AbstractWidget
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

getChildren

public Iterator getChildren()
Description copied from interface: ContainerWidget
Returns an iterator over the widgets this object contains

Specified by:
getChildren in interface ContainerWidget


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