org.apache.tapestry.components
Class ForBean

java.lang.Object
  extended by org.apache.hivemind.impl.BaseLocatable
      extended by org.apache.tapestry.AbstractComponent
          extended by org.apache.tapestry.form.AbstractFormComponent
              extended by org.apache.tapestry.components.ForBean
All Implemented Interfaces:
Locatable, LocationHolder, IFormComponent, IComponent, IDirectEvent, IRender

public abstract class ForBean
extends AbstractFormComponent

Since:
4.0
Author:
mb
See Also:
IPrimaryKeyConverter, DefaultPrimaryKeyConverter

Nested Class Summary
protected  class ForBean.CompleteRepSource
          An implementation of RepSource that provides the string representation of the given value using all methods.
protected  class ForBean.KeyExpressionRepSource
          An implementation of RepSource that provides the string representation of the given value using just the 'keyExpression' parameter.
protected static interface ForBean.RepSource
          An interface that provides the string representation of a given value.
 
Field Summary
 
Fields inherited from class org.apache.tapestry.AbstractComponent
_clientId
 
Constructor Summary
ForBean()
           
 
Method Summary
protected  Iterator evaluateFullSourceIterator()
          Returns a new iterator of the values in 'fullSource'.
protected  Iterator evaluateSourceIterator()
          Returns a new iterator of the values in 'source'.
protected  Object findValueWithStringRep(Iterator sourceIterator, Iterator fullSourceIterator, Map repToValueMap, String rep, ForBean.RepSource repSource)
          Attempt to find a value in 'source' or 'fullSource' that generates the provided string representation.
protected  Object findValueWithStringRepInIterator(Iterator it, Map repToValueMap, String rep, ForBean.RepSource repSource)
          Attempt to find a value in the provided collection that generates the required string representation.
protected  boolean getCanTakeFocus()
          For component can not take focus.
 String getClientId()
          Returns the component's client-side element id.
abstract  IPrimaryKeyConverter getConverter()
           
protected  Object getConverterFromValue(Object value)
          Uses the 'converter' parameter to determine the primary key of the given value.
abstract  DataSqueezer getDataSqueezer()
           
abstract  Object getDefaultValue()
           
 String getDisplayName()
          May be implemented to return a user-presentable, localized name for the component, which is used in labels or error messages.
abstract  String getElement()
           
abstract  ExpressionEvaluator getExpressionEvaluator()
           
 int getIndex()
          The index number, within the source, of the the current value.
abstract  String getKeyExpression()
           
protected  Object getKeyExpressionFromValue(Object value)
          Uses the 'keyExpression' parameter to determine the primary key of the given value.
abstract  boolean getMatch()
           
protected  Object getPrimaryKeyFromValue(Object value)
          Returns the primary key of the given value.
protected  Iterator getStoredData(IRequestCycle cycle, String name)
          Returns a list of the values stored as Hidden fields in the form.
protected  String getStringRepFromValue(Object value)
          Returns the string representation of the value.
 Object getValue()
          Returns the most recent value extracted from the source parameter.
abstract  ValueConverter getValueConverter()
           
protected  Object getValueFromStringRep(Iterator sourceIterator, Iterator fullSourceIterator, Map repToValueMap, String rep)
          Determines the value that corresponds to the given string representation.
abstract  boolean getVolatile()
           
 boolean isDisabled()
          Returns true if the component is disabled.
protected  void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
          Gets the source binding and iterates through its values.
protected  void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
          Invoked from AbstractFormComponent.renderComponent(IMarkupWriter, IRequestCycle) to render the component.
protected  void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
          Invoked from AbstractFormComponent.renderComponent(IMarkupWriter, IRequestCycle) to rewind the component.
protected  Iterator storeSourceData(IForm form, String name)
          Stores the provided data in the form and then returns the data as an iterator.
protected  void updateOutputParameters()
          Updates the index and value output parameters if bound.
protected  void updatePrimaryKeysParameter(String[] stringReps)
          Updates the primaryKeys parameter if bound.
 
Methods inherited from class org.apache.tapestry.form.AbstractFormComponent
getForm, getIdParameter, getName, getRenderBodyOnRewind, isRequired, renderDelegateAttributes, renderDelegatePrefix, renderDelegateSuffix, renderIdAttribute, setForm, setName, setName
 
Methods inherited from class org.apache.tapestry.AbstractComponent
addAsset, addBody, addComponent, checkActiveLock, cleanupAfterRender, enterActiveState, finishLoad, finishLoad, getAsset, getAssets, getBeans, getBinding, getBindingNames, getBindings, getBody, getBodyCount, getComponent, getComponents, getContainedComponent, getContainer, getEventInvoker, getExtendedId, getId, getIdPath, getListeners, getMessages, getNamespace, getPage, getRenderWorker, getSpecification, isInActiveState, isParameterBound, isRendering, isStateful, pageEndRender, prepareForRender, render, renderBody, renderInformalParameters, setBinding, setClientId, setContainedComponent, setContainer, setId, setNamespace, setPage, toString, triggerEvent
 
Methods inherited from class org.apache.hivemind.impl.BaseLocatable
getLocation, setLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.tapestry.IComponent
addAsset, addBody, addComponent, enterActiveState, finishLoad, getAsset, getAssets, getBeans, getBinding, getBindingNames, getBindings, getComponent, getComponents, getContainedComponent, getContainer, getEventInvoker, getExtendedId, getId, getIdPath, getListeners, getMessages, getNamespace, getPage, getSpecification, isRendering, renderBody, setBinding, setContainedComponent, setContainer, setId, setNamespace, setPage
 
Methods inherited from interface org.apache.tapestry.IRender
render
 
Methods inherited from interface org.apache.hivemind.LocationHolder
setLocation
 
Methods inherited from interface org.apache.hivemind.Locatable
getLocation
 

Constructor Detail

ForBean

public ForBean()
Method Detail

getElement

public abstract String getElement()

getKeyExpression

public abstract String getKeyExpression()

getConverter

public abstract IPrimaryKeyConverter getConverter()

getDefaultValue

public abstract Object getDefaultValue()

getMatch

public abstract boolean getMatch()

getVolatile

public abstract boolean getVolatile()

getDataSqueezer

public abstract DataSqueezer getDataSqueezer()

getValueConverter

public abstract ValueConverter getValueConverter()

getExpressionEvaluator

public abstract ExpressionEvaluator getExpressionEvaluator()

renderComponent

protected void renderComponent(IMarkupWriter writer,
                               IRequestCycle cycle)
Gets the source binding and iterates through its values. For each, it updates the value binding and render's its wrapped elements.

Overrides:
renderComponent in class AbstractFormComponent
See Also:
AbstractComponent.renderComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)

getValue

public final Object getValue()
Returns the most recent value extracted from the source parameter.

Throws:
org.apache.tapestry.ApplicationRuntimeException - if the For is not currently rendering.

getIndex

public int getIndex()
The index number, within the source, of the the current value.

Throws:
org.apache.tapestry.ApplicationRuntimeException - if the For is not currently rendering.

isDisabled

public boolean isDisabled()
Description copied from interface: IFormComponent
Returns true if the component is disabled. This is important when the containing form is submitted, since disabled parameters do not update their bindings.


updateOutputParameters

protected void updateOutputParameters()
Updates the index and value output parameters if bound.


updatePrimaryKeysParameter

protected void updatePrimaryKeysParameter(String[] stringReps)
Updates the primaryKeys parameter if bound.


renderFormComponent

protected void renderFormComponent(IMarkupWriter writer,
                                   IRequestCycle cycle)
Description copied from class: AbstractFormComponent
Invoked from AbstractFormComponent.renderComponent(IMarkupWriter, IRequestCycle) to render the component.

Specified by:
renderFormComponent in class AbstractFormComponent

rewindFormComponent

protected void rewindFormComponent(IMarkupWriter writer,
                                   IRequestCycle cycle)
Description copied from class: AbstractFormComponent
Invoked from AbstractFormComponent.renderComponent(IMarkupWriter, IRequestCycle) to rewind the component. If the component is disabled this will not be invoked.

Specified by:
rewindFormComponent in class AbstractFormComponent

getStoredData

protected Iterator getStoredData(IRequestCycle cycle,
                                 String name)
Returns a list of the values stored as Hidden fields in the form. A conversion is performed if the primary key of the value is stored.

Parameters:
cycle - The current request cycle
name - The name of the HTTP parameter whether the values
Returns:
an iterator with the values stored in the provided Hidden fields

storeSourceData

protected Iterator storeSourceData(IForm form,
                                   String name)
Stores the provided data in the form and then returns the data as an iterator. If the primary key of the value can be determined, then that primary key is saved instead.

Parameters:
form - The form where the data will be stored
name - The name under which the data will be stored
Returns:
an iterator with the bound values stored in the form

getStringRepFromValue

protected String getStringRepFromValue(Object value)
Returns the string representation of the value. The first letter of the string representation shows whether a value or a primary key is being described.

Parameters:
value -
Returns:

getPrimaryKeyFromValue

protected Object getPrimaryKeyFromValue(Object value)
Returns the primary key of the given value. Uses the 'keyExpression' or the 'converter' (if either is provided).

Parameters:
value - The value from which the primary key should be extracted
Returns:
The primary key of the value, or null if such cannot be extracted.

getKeyExpressionFromValue

protected Object getKeyExpressionFromValue(Object value)
Uses the 'keyExpression' parameter to determine the primary key of the given value.

Parameters:
value - The value from which the primary key should be extracted
Returns:
The primary key of the value as defined by 'keyExpression', or null if such cannot be extracted.

getConverterFromValue

protected Object getConverterFromValue(Object value)
Uses the 'converter' parameter to determine the primary key of the given value.

Parameters:
value - The value from which the primary key should be extracted
Returns:
The primary key of the value as provided by the converter, or null if such cannot be extracted.

getValueFromStringRep

protected Object getValueFromStringRep(Iterator sourceIterator,
                                       Iterator fullSourceIterator,
                                       Map repToValueMap,
                                       String rep)
Determines the value that corresponds to the given string representation. If the 'match' parameter is true, attempt to find a value in 'source' or 'fullSource' that generates the same string representation. Otherwise, create a new value from the string representation.

Parameters:
rep - the string representation for which a value should be returned
Returns:
the value that corresponds to the provided string representation

findValueWithStringRep

protected Object findValueWithStringRep(Iterator sourceIterator,
                                        Iterator fullSourceIterator,
                                        Map repToValueMap,
                                        String rep,
                                        ForBean.RepSource repSource)
Attempt to find a value in 'source' or 'fullSource' that generates the provided string representation. Use the RepSource interface to determine what the string representation of a particular value is.

Parameters:
rep - the string representation for which a value should be returned
repSource - an interface providing the string representation of a given value
Returns:
the value in 'source' or 'fullSource' that corresponds to the provided string representation

findValueWithStringRepInIterator

protected Object findValueWithStringRepInIterator(Iterator it,
                                                  Map repToValueMap,
                                                  String rep,
                                                  ForBean.RepSource repSource)
Attempt to find a value in the provided collection that generates the required string representation. Use the RepSource interface to determine what the string representation of a particular value is.

Parameters:
rep - the string representation for which a value should be returned
repSource - an interface providing the string representation of a given value
it - the iterator of the collection in which a value should be searched
Returns:
the value in the provided collection that corresponds to the required string representation

evaluateSourceIterator

protected Iterator evaluateSourceIterator()
Returns a new iterator of the values in 'source'.

Returns:
the 'source' iterator

evaluateFullSourceIterator

protected Iterator evaluateFullSourceIterator()
Returns a new iterator of the values in 'fullSource'.

Returns:
the 'fullSource' iterator

getCanTakeFocus

protected boolean getCanTakeFocus()
For component can not take focus.

Overrides:
getCanTakeFocus in class AbstractFormComponent

getClientId

public String getClientId()
Description copied from class: AbstractComponent
Returns the component's client-side element id. This has traditionally been an IFormComponent only binding but now applies to all components. The method should check to see if any id parameter/property has been set already and use that above all others, falling back to IComponent.getId() if nothing else is found.

Specified by:
getClientId in interface IFormComponent
Specified by:
getClientId in interface IComponent
Overrides:
getClientId in class AbstractComponent
Returns:
the id, or null if the component doesn't support a client id.

getDisplayName

public String getDisplayName()
Description copied from interface: IFormComponent
May be implemented to return a user-presentable, localized name for the component, which is used in labels or error messages. Most components simply return null.



Copyright © 2006 Apache Software Foundation. All Rights Reserved.