Class WRepeater
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.WRepeater
-
- All Implemented Interfaces:
AjaxTarget,BeanAware,BeanBound,BeanProviderBound,Container,DataBound,NamingContextable,WComponent,WebComponent,Serializable
- Direct Known Subclasses:
WList,WTable.TableRepeater,WTableRepeater
public class WRepeater extends WBeanComponent implements Container, AjaxTarget, NamingContextable
When you have a situation where you have a list of a repeated data type that you want to render or edit, then this ui component can help.Typical usage:
WRepeater repeater = new WRepeater(); repeater.setRepeatedComponent(new MyRepeatedComponent()); ... repeater.setData(myBeanList);
- Since:
- 1.0.0
- Author:
- Ming Gao, Martin Shevchenko
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWRepeater.RepeaterModelHolds the extrinsic state information of a WRepeater.static classWRepeater.SubUIContextThe SubUIContext stores the state information for the repeated component hierarchy for a single row in the repeater.static classWRepeater.WRepeatRootComponent to hold the repeated component and provide the correct row data.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Constructor Summary
Constructors Constructor Description WRepeater()Creates a WRepeater without any repeated component.WRepeater(WComponent repeatedComponent)Creates a WRepeater which will repeat the given component.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcleanupStaleContexts(Set<?> rowIds)Removes any stale contexts from the row context map.protected voidclearScratchMaps(WComponent node)Recursively clears cached component scratch maps.ListgetBeanList()Retrieves the list of dataBeans that holds the data object for each row.WComponentgetChildAt(int index)Retrieves a child component by its index.intgetChildCount()List<WComponent>getChildren()Retrieves a list of this Container's.protected WRepeater.RepeaterModelgetComponentModel()Returns the effective component model for this component.intgetIndexOfChild(WComponent childComponent)Retrieves the index of the given child.StringgetNamingContextId()Allow components that implementNamingContextableto selectively disable prepending their ID to their descendent's IDs by breaking the prepending logic into a seperately callable method.protected WRepeater.RepeaterModelgetOrCreateComponentModel()Retrieves the model for this component so that it can be modified.WComponentgetRepeatedComponent()Retrieves the repeated component, that is used to render each row.WComponentgetRepeatedComponent(int row)Retrieves the repeated component for the specified row.protected WRepeater.WRepeatRootgetRepeatRoot()Retrieves the repeat root, creating one if necessary.ObjectgetRowBeanForSubcontext(WRepeater.SubUIContext subContext)Returns the row data for the given row context.UIContextgetRowContext(Object rowBean)Retrieves the UIContext for a row, where the row index is not known.UIContextgetRowContext(Object rowBean, int rowIndex)Retrieves the UIContext for a row.List<UIContext>getRowContexts()Retrieves the row contexts for all rows.protected ObjectgetRowId(Object rowBean)Retrieves the row id for the given row.protected StringgetRowIdName(Object rowBean, Object rowId)Allows a subclass to provide the ID used in the row naming context.voidhandleRequest(Request request)Override handleRequest to process the request for each row.booleanisNamingContext()A naming context is only considered active if an Id name has been set.protected WRepeater.RepeaterModelnewComponentModel()Creates a new component model which is appropriate for this component.protected voidpreparePaintComponent(Request request)Override preparePaintComponent to prepare each row for painting.protected voidprepareRow(Request request, int rowIndex)Prepares a single row for painting.voidsetBeanList(List beanList)Remember the list of beans that hold the data object for each row.voidsetData(Object dataBean)Remember the list of dataBeans that holds the data object for each row.voidsetNamingContext(boolean context)A naming context is only considered active if it has been set active viasetNamingContext(boolean)and also has an id name set viaAbstractWComponent.setIdName(String).voidsetRepeatedComponent(WComponent repeatedComponent)Set the wcomponent instance capable of handling a row.voidsetRowIdProperty(String rowIdProperty)Sets the bean property that can be used to obtain each row's unique id.voidshowErrorIndicators(List<Diagnostic> diags)Visually marks any fields or blocks that have errors in the given diag list.voidtidyUpUIContext()Removes any component models that are in their default state.StringtoString()Creates a String representation of this component; usually for debugging purposes.voidupdateBeanValue()Override updateBeanValue to update the bean value for all WBeanComponents Updates the bean value with the value returned byWBeanComponent.getData().voidvalidate(List<Diagnostic> diags)Validates each row.-
Methods inherited from class com.github.bordertech.wcomponents.WBeanComponent
addBeanToScratchMap, doUpdateBeanValue, getBean, getBeanFromScratchMap, getBeanId, getBeanProperty, getBeanProvider, getBeanScratchMap, getBeanValue, getData, isBeanInScratchMap, isChanged, isSearchAncestors, isUseRequestScopeScratchMap, removeBeanFromScratchMap, resetData, setBean, setBeanId, setBeanProperty, setBeanProvider, setSearchAncestors
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicatorsForComponent, showWarningIndicators, showWarningIndicatorsForComponent, tidyUpUIContextForTree, validateComponent, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showWarningIndicators, tidyUpUIContextForTree
-
-
-
-
Constructor Detail
-
WRepeater
public WRepeater()
Creates a WRepeater without any repeated component. The methodsetRepeatedComponent(WComponent)must be called to configure the repeater.
-
WRepeater
public WRepeater(WComponent repeatedComponent)
Creates a WRepeater which will repeat the given component.- Parameters:
repeatedComponent- the component to repeat.
-
-
Method Detail
-
setRepeatedComponent
public void setRepeatedComponent(WComponent repeatedComponent)
Set the wcomponent instance capable of handling a row. The component must implement at least one of theDataBound,BeanBoundorBeanProviderBoundinterfaces. The data entries in the bean list passed to this repeater must be compatible with the component.- Parameters:
repeatedComponent- the component to repeat.
-
setBeanList
public void setBeanList(List beanList)
Remember the list of beans that hold the data object for each row.- Parameters:
beanList- the list of data objects for each row.
-
clearScratchMaps
protected void clearScratchMaps(WComponent node)
Recursively clears cached component scratch maps. This is called when the bean list changes, as the beans may have changed.- Parameters:
node- the component branch to clear cached data in.
-
getBeanList
public List getBeanList()
Retrieves the list of dataBeans that holds the data object for each row. The list returned will be the same instance as the one supplied via the setBeanList method. Will never return null, but it can return an empty list.- Returns:
- the list of dataBeans that holds the data object for each row
-
updateBeanValue
public void updateBeanValue()
Override updateBeanValue to update the bean value for all WBeanComponents Updates the bean value with the value returned byWBeanComponent.getData().- Overrides:
updateBeanValuein classWBeanComponent
-
setData
public void setData(Object dataBean)
Remember the list of dataBeans that holds the data object for each row.- Specified by:
setDatain interfaceDataBound- Overrides:
setDatain classWBeanComponent- Parameters:
dataBean- Must be a java.util.List of dataBeans.
-
validate
public void validate(List<Diagnostic> diags)
Validates each row.- Specified by:
validatein interfaceWComponent- Overrides:
validatein classAbstractWComponent- Parameters:
diags- the list of SfpDiagnostics to add to.
-
showErrorIndicators
public void showErrorIndicators(List<Diagnostic> diags)
Visually marks any fields or blocks that have errors in the given diag list.- Specified by:
showErrorIndicatorsin interfaceWComponent- Overrides:
showErrorIndicatorsin classAbstractWComponent- Parameters:
diags- the list of SfpDiagnostics from the last validation pass.
-
handleRequest
public void handleRequest(Request request)
Override handleRequest to process the request for each row.- Specified by:
handleRequestin interfaceWComponent- Overrides:
handleRequestin classAbstractWComponent- Parameters:
request- the request being responded to.
-
cleanupStaleContexts
protected void cleanupStaleContexts(Set<?> rowIds)
Removes any stale contexts from the row context map.- Parameters:
rowIds- the current set of row Ids.
-
tidyUpUIContext
public void tidyUpUIContext()
Removes any component models that are in their default state.The subContexts are held onto as they hold the "render id" for the row. This is needed to be able to match the rendered row back to the subcontext.
- Overrides:
tidyUpUIContextin classAbstractWComponent
-
preparePaintComponent
protected void preparePaintComponent(Request request)
Override preparePaintComponent to prepare each row for painting.- Overrides:
preparePaintComponentin classAbstractWComponent- Parameters:
request- the request being responded to.
-
prepareRow
protected void prepareRow(Request request, int rowIndex)
Prepares a single row for painting.- Parameters:
request- the request being responded to.rowIndex- the row index.
-
getRowIdName
protected String getRowIdName(Object rowBean, Object rowId)
Allows a subclass to provide the ID used in the row naming context.The returned ID must only contain letters, digits or underscores.
- Parameters:
rowBean- the row's beanrowId- the row id- Returns:
- the unique row id or null to use the row context id
-
setRowIdProperty
public void setRowIdProperty(String rowIdProperty)
Sets the bean property that can be used to obtain each row's unique id.- Parameters:
rowIdProperty- the row id property, using jakarta PropertyUtils notation
-
newComponentModel
protected WRepeater.RepeaterModel newComponentModel()
Creates a new component model which is appropriate for this component.- Overrides:
newComponentModelin classWBeanComponent- Returns:
- a new RepeaterModel.
-
getComponentModel
protected WRepeater.RepeaterModel getComponentModel()
Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.- Overrides:
getComponentModelin classWBeanComponent- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WRepeater.RepeaterModel getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.- Overrides:
getOrCreateComponentModelin classWBeanComponent- Returns:
- the model for this component
-
getRowContext
public UIContext getRowContext(Object rowBean)
Retrieves the UIContext for a row, where the row index is not known.- Parameters:
rowBean- the row's bean.- Returns:
- The context for the given row.
-
getRowContext
public UIContext getRowContext(Object rowBean, int rowIndex)
Retrieves the UIContext for a row.- Parameters:
rowBean- the row's bean.rowIndex- the row index.- Returns:
- The context for the given row.
-
getRowBeanForSubcontext
public Object getRowBeanForSubcontext(WRepeater.SubUIContext subContext)
Returns the row data for the given row context.- Parameters:
subContext- the row context.- Returns:
- the data bean for the given row context.
-
getRowId
protected Object getRowId(Object rowBean)
Retrieves the row id for the given row.- Parameters:
rowBean- the row's data.- Returns:
- the id for the given row. Defaults to the row data.
-
getRowContexts
public List<UIContext> getRowContexts()
Retrieves the row contexts for all rows.- Returns:
- A list containing a UIContext for each row. Will never return null, but it can return an empty list.
-
getRepeatRoot
protected WRepeater.WRepeatRoot getRepeatRoot()
Retrieves the repeat root, creating one if necessary.- Returns:
- the repeat root.
-
getRepeatedComponent
public WComponent getRepeatedComponent()
Retrieves the repeated component, that is used to render each row.- Returns:
- the repeated component
-
getRepeatedComponent
public WComponent getRepeatedComponent(int row)
Retrieves the repeated component for the specified row.- Parameters:
row- the row number.- Returns:
- the repeated component for the specified row.
-
getChildCount
public int getChildCount()
- Specified by:
getChildCountin interfaceContainer- Returns:
- the number of child components currently contained within this component.
-
getChildAt
public WComponent getChildAt(int index)
Retrieves a child component by its index.- Specified by:
getChildAtin interfaceContainer- Parameters:
index- the index of the child component to be retrieved.- Returns:
- the child component at the given index.
-
getIndexOfChild
public int getIndexOfChild(WComponent childComponent)
Retrieves the index of the given child.- Specified by:
getIndexOfChildin interfaceContainer- Parameters:
childComponent- the child component to retrieve the index for.- Returns:
- the index of the given child component, or -1 if the component is not a child of this component.
-
getChildren
public List<WComponent> getChildren()
Retrieves a list of this Container's.- Specified by:
getChildrenin interfaceContainer- Returns:
- an immutable list of this Container.
-
toString
public String toString()
Description copied from class:AbstractWComponentCreates a String representation of this component; usually for debugging purposes.- Overrides:
toStringin classAbstractWComponent- Returns:
- a String representation of this component, for debugging purposes.
-
setNamingContext
public void setNamingContext(boolean context)
A naming context is only considered active if it has been set active viasetNamingContext(boolean)and also has an id name set viaAbstractWComponent.setIdName(String).- Parameters:
context- set true if this is a naming context.
-
isNamingContext
public boolean isNamingContext()
A naming context is only considered active if an Id name has been set.- Specified by:
isNamingContextin interfaceNamingContextable- Returns:
- true if active naming context.
-
getNamingContextId
public String getNamingContextId()
Allow components that implementNamingContextableto selectively disable prepending their ID to their descendent's IDs by breaking the prepending logic into a seperately callable method.See
WComponent.getId()for usage.By default, this method will call through to
WComponent.getId()and return the result.- Specified by:
getNamingContextIdin interfaceNamingContextable- Returns:
- by default, return getId().
-
-