|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.chainedoptions.AbstractChainedOption
public abstract class AbstractChainedOption
Abstract class that implements the ChainedOption interface and provides an
implementation of updateValue(Object, List, Object)
. This
implementation loops through the list of options and checks if the
commandProperty
in the command
object matches
any item in the list. If it doesn't, a default value is set in the command
object. The default value is provided by the ChainedOptionStrategy
retrieved from the getStrategy(Object)
method.
Subclasses must implement the method retrieveOptions(Object, Object)
method. Below is an example of such an implementation:
package com.acme.valuehandler; import java.util.List; import com.acme.valuehandler.config.RegionConfig; public class CountryChainedOption extends AbstractChainedOption { private RegionConfig regionConfig; private String regionProperty; public List retrieveOptions(Object command) { String region = getProperty(command, regionProperty); List countryBeans = regionConfig.getCountries(region); List countries = getConverter().convert(countryBeans); return getStrategy().adjustAndSort(countries); } }
Constructor Summary | |
---|---|
AbstractChainedOption()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Checks if all necessary properties have been set. |
java.lang.String |
getCommandProperty()
|
BeanConverter |
getConverter()
|
java.lang.String |
getOptionsKey()
Get the key that identifies the list of options corresponding to this ChainedOption . |
protected java.lang.Object |
getProperty(java.lang.Object bean,
java.lang.String property)
Utility method that gets a named property from a given object. |
ChainedOptionStrategy |
getStrategy(java.lang.Object command)
Override this if the implementation has several strategies. |
protected void |
initChainedOption()
Template method that subclasses may implement to ensure proper initialization. |
protected boolean |
matches(LabelValueBean bean,
java.lang.String value)
Utility method that matches the value of the given bean
with the specified value . |
abstract java.util.List |
retrieveOptions(java.lang.Object command,
java.lang.Object context)
Retrieve a value List for this ChainedOption corresponding to the current values in the command that this ChainedOption
depends on. |
void |
setCommandProperty(java.lang.String commandProperty)
Set the property on the target command object managed by
this instance. |
void |
setConverter(BeanConverter converter)
Set the BeanConverter that should be used for translating
to LabelValueBeans. |
void |
setDefaultStrategy(ChainedOptionStrategy defaultStrategy)
Set the default strategy to use. |
void |
setOptionsKey(java.lang.String optionsKey)
Set the key that should identify the option list managed by this instance. |
protected void |
setProperty(java.lang.Object bean,
java.lang.String propertyName,
java.lang.Object value)
Utility method that sets a named property on a given object. |
void |
updateValue(java.lang.Object command,
java.util.List options,
java.lang.Object context)
Default implementation of updateValue , which loops
through the list of available options and compares them to the current
value of the managed attribute in the command object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractChainedOption()
Method Detail |
---|
public abstract java.util.List retrieveOptions(java.lang.Object command, java.lang.Object context)
ChainedOption
command
that this ChainedOption
depends on. This method may use a BeanConverter
to translate Java
Beans to LabelValueBean
objects and an
ChainedOptionStrategy
to perform additional modifications to the
option list.
retrieveOptions
in interface ChainedOption
command
- Command object to use when extracting values that the
ChainedOption
depends on.context
- may contain any context that might be interesting for
retreiving valid options. E.g. a
HttpServletRequest
object can be supplied as
context for a Strategy to perform filtering based on user
access.
LabelValueBean
objects.public void updateValue(java.lang.Object command, java.util.List options, java.lang.Object context)
updateValue
, which loops
through the list of available options and compares them to the current
value of the managed attribute in the command
object.
If the selected value is present in the list, no modifications are done
in the command
, otherwise a default value is retrieved by
calling ChainedOptionStrategy.getDefaultValue(List, Object)
, and
the commandProperty
in the command
is set
to this value.
updateValue
in interface ChainedOption
command
- the object which will possibly be updated with a new object.options
- the list of options with which the managed value in the
command
will be compared.context
- a context that will be supplied to the
ChainedOptionStrategy
for selecting an
appropriate default value.ChainedOptionStrategy.getDefaultValue(List, Object)
protected boolean matches(LabelValueBean bean, java.lang.String value)
bean
with the specified value
.
bean
- The LabelValueBean
to match the value against.value
- The value to match.
true
if the values match.public final void afterPropertiesSet() throws java.lang.Exception
initChainedOption()
if additional integrity checks are
needed on initialization.
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.IllegalArgumentException
- if any mandatory property has not been set.
java.lang.Exception
protected void initChainedOption()
protected void setProperty(java.lang.Object bean, java.lang.String propertyName, java.lang.Object value)
bean
- The object to set the property on.propertyName
- The name of the property to set.value
- The value that the property will be set to.protected java.lang.Object getProperty(java.lang.Object bean, java.lang.String property)
bean
- The object to get the property from.property
- The name of the property to get.
public java.lang.String getCommandProperty()
public void setCommandProperty(java.lang.String commandProperty)
command
object managed by
this instance.
commandProperty
- The commandProperty to set.public java.lang.String getOptionsKey()
ChainedOption
ChainedOption
.
getOptionsKey
in interface ChainedOption
public void setOptionsKey(java.lang.String optionsKey)
optionsKey
- The optionsKey to set.public BeanConverter getConverter()
public void setConverter(BeanConverter converter)
BeanConverter
that should be used for translating
to LabelValueBeans.
converter
- The converter to set.public ChainedOptionStrategy getStrategy(java.lang.Object command)
getStrategy
in interface ChainedOption
command
- the command to use for selecting the correct Strategy.
defaultStrategy
.public void setDefaultStrategy(ChainedOptionStrategy defaultStrategy)
defaultStrategy
- the default strategy to set.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |