Class WBeanComponent
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- All Implemented Interfaces:
BeanAware,BeanBound,BeanProviderBound,DataBound,WComponent,WebComponent,Serializable
- Direct Known Subclasses:
AbstractInput,WButton,WContainer,WDataTable,WHiddenComment,WImage,WLink,WProgressBar,WRadioButton,WRepeater,WRepeater.WRepeatRoot,WTable,WTemplate,WText
public class WBeanComponent extends AbstractWComponent implements DataBound, BeanBound, BeanProviderBound
WBeanComponent provides a default implementation of a bean-aware component, and is the basis for most bean-aware WComponents. It can be used as a starting point for custom application bean-aware components.A fix has been made to the logic for a bean container, that has a bean property set, to pass the correct bean value to its child bean components. This fix is an "opt in". To enable the correct bean container logic set the parameter "bordertech.wcomponents.bean.logic.correct=true".
- Since:
- 1.0.0
- Author:
- Yiannis Paschalidis, Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
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 WBeanComponent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddBeanToScratchMap(Object beanId, Object bean)protected voiddoUpdateBeanValue(Object value)Updates the bean value with the new value.ObjectgetBean()Retrieves the bean.protected ObjectgetBeanFromScratchMap()ObjectgetBeanId()Retrieves the bean id associated with this component.StringgetBeanProperty()Retrieves the bean property that this component is interested in.BeanProvidergetBeanProvider()protected Map<Object,Object>getBeanScratchMap()ObjectgetBeanValue()Retrieves the bean value.protected BeanAndProviderBoundComponentModelgetComponentModel()Returns the effective component model for this component.ObjectgetData()Returns the data for this component.protected BeanAndProviderBoundComponentModelgetOrCreateComponentModel()Retrieves the model for this component so that it can be modified.protected booleanisBeanInScratchMap(Object beanId)booleanisChanged()Indicates whether this component's data has changed from the default value.booleanisSearchAncestors()Flag to indicate if a bean should be searched for up the component tree.protected booleanisUseRequestScopeScratchMap()protected BeanAndProviderBoundComponentModelnewComponentModel()Creates a new model appropriate for this component.protected voidremoveBeanFromScratchMap()Remove the bean from the scratch maps.voidresetData()Resets the data back to the default value, which may either be from a bean or the shared model.voidsetBean(Object bean)Sets the bean associated with this WBeanComponent.voidsetBeanId(Object beanId)Sets the bean id associated with this WBeanComponent.voidsetBeanProperty(String propertyName)Sets the bean property that this component is interested in.voidsetBeanProvider(BeanProvider beanProvider)Sets theBeanProviderassociated with this WBeanComponent.voidsetData(Object data)Sets the data that this component displays/edits.voidsetSearchAncestors(boolean search)voidupdateBeanValue()Updates the bean value with the value returned bygetData().-
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, handleRequest, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, preparePaintComponent, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showErrorIndicatorsForComponent, showWarningIndicators, showWarningIndicatorsForComponent, tidyUpUIContext, tidyUpUIContextForTree, toString, validate, validateComponent, writeReplace
-
-
-
-
Method Detail
-
getBean
public Object getBean()
Retrieves the bean. The following are searched in order:
- a bean set explicitly using
setBean; - a bean cached in the scratch map;
- a bean provided by a BeanProvider (and subsequently cached in the scratch map);
- a bean provided by a bean-aware parent component (and subsequently cached in the scratch map).
- a bean set explicitly using
-
setBean
public void setBean(Object bean)
Sets the bean associated with this WBeanComponent. This method of bean association is discouraged, as the bean will be stored in the user's session. A better alternative is to provide a BeanProvider and a Bean Id.
-
setBeanId
public void setBeanId(Object beanId)
Sets the bean id associated with this WBeanComponent. This bean id will be used to obtain the bean from the associatedBeanProviderwhenever the bean data is required.- Specified by:
setBeanIdin interfaceBeanProviderBound- Parameters:
beanId- the bean id to associate- See Also:
BeanProviderBound
-
getBeanId
public Object getBeanId()
Retrieves the bean id associated with this component. This method will be used by aBeanProviderto retrieve the bean.- Specified by:
getBeanIdin interfaceBeanProviderBound- Returns:
- the bean Id associated with this component
-
setBeanProperty
public void setBeanProperty(String propertyName)
Sets the bean property that this component is interested in. The bean property is expressed in Jakarta PropertyUtils bean notation, with an extension of "." to indicate that the bean itself should be used.- Specified by:
setBeanPropertyin interfaceBeanAware- Parameters:
propertyName- the bean property, in Jakarta PropertyUtils bean notation
-
getBeanProperty
public String getBeanProperty()
Retrieves the bean property that this component is interested in.- Specified by:
getBeanPropertyin interfaceBeanAware- Returns:
- the bean property, in Jakarta PropertyUtils bean notation
-
isSearchAncestors
public boolean isSearchAncestors()
Flag to indicate if a bean should be searched for up the component tree. If set true and the current component does not have a bean, then ask the next bean aware ancestor for its bean. If false and the component does not have a bean, then do not search the tree for a bean and return null.Setting this to false at the correct bean container level can stop a bean component going up the whole component tree looking for its bean and being given the wrong bean.
- Specified by:
isSearchAncestorsin interfaceBeanBound- Returns:
- true if search ancestors for a bean, otherwise false to not search
-
setSearchAncestors
public void setSearchAncestors(boolean search)
- Parameters:
search- true if search ancestors for the components bean
-
setBeanProvider
public void setBeanProvider(BeanProvider beanProvider)
Sets theBeanProviderassociated with this WBeanComponent. The bean provider will be called to supply the bean whenever necessary.- Specified by:
setBeanProviderin interfaceBeanProviderBound- Parameters:
beanProvider- the bean provider to associate
-
getBeanProvider
public BeanProvider getBeanProvider()
- Returns:
- the associated bean provider, or null
-
getData
public Object getData()
Returns the data for this component. The following are searched in order:- a value set explicitly in the ui context using
setData(Object); - if a bean is available; the bean's value; or
- the value set on the shared model.
- a value set explicitly in the ui context using
-
setData
public void setData(Object data)
Sets the data that this component displays/edits. For bean aware components, this should only be called from handleRequest to set user-entered data.
-
getBeanValue
public Object getBeanValue()
Retrieves the bean value. The value is (temporarily) cached in the scratch map to speed up subsequent accesses.- Specified by:
getBeanValuein interfaceBeanAware- Returns:
- the bean value, or null if no bean value is available
-
updateBeanValue
public void updateBeanValue()
Updates the bean value with the value returned bygetData().
-
doUpdateBeanValue
protected void doUpdateBeanValue(Object value)
Updates the bean value with the new value.- Parameters:
value- the new value with which to update the bean
-
isUseRequestScopeScratchMap
protected boolean isUseRequestScopeScratchMap()
- Returns:
- true if use request scope scratch map to hold bean provider results
-
removeBeanFromScratchMap
protected void removeBeanFromScratchMap()
Remove the bean from the scratch maps.
-
isBeanInScratchMap
protected boolean isBeanInScratchMap(Object beanId)
- Parameters:
beanId- check if this bean id is in the scratch map- Returns:
- true if current bean is in the scratch map
-
getBeanFromScratchMap
protected Object getBeanFromScratchMap()
- Returns:
- the bean from the scratch map
-
addBeanToScratchMap
protected void addBeanToScratchMap(Object beanId, Object bean)
- Parameters:
beanId- the bean id to put in the scratch mapbean- the bean to put in the scratch map
-
getBeanScratchMap
protected Map<Object,Object> getBeanScratchMap()
- Returns:
- the scratch map with the correct scope.
-
isChanged
public boolean isChanged()
Indicates whether this component's data has changed from the default value. TODO: This needs to be added to the databound interface after the bulk of the components have been converted.- Returns:
- true if this component's current value differs from the default value for the given context.
-
resetData
public void resetData()
Resets the data back to the default value, which may either be from a bean or the shared model.
-
newComponentModel
protected BeanAndProviderBoundComponentModel newComponentModel()
Creates a new model appropriate for this component.- Overrides:
newComponentModelin classAbstractWComponent- Returns:
- a new
BeanAndProviderBoundComponentModel.
-
getComponentModel
protected BeanAndProviderBoundComponentModel 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 classAbstractWComponent- Returns:
- the effective component model
-
getOrCreateComponentModel
protected BeanAndProviderBoundComponentModel 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 classAbstractWComponent- Returns:
- the model for this component
-
-