public abstract class ViewSupport<T> extends Object implements View<T>, ControlChangeListener, BinderHolder, Serializable
View implementation.
The central method is buildPanel that builds the JComponent
that hold the view controls. You may use custom binding of the view overwriting the methods
doUpdate and doRefresh.
For common binding code, you usually use autobinding facitility, that is, using
the same name to the field control and model property name and calling to autobind() method.
When using autobinding, you may exclude model properties from binding using some
of ignoreProperty methods.
Manual binding is also supported via bind methods. When binding a control, a
the View is added to control as ChangeListener is added to the control for setting dirty property on control
changes.
Only org.springframework.util.validation.Validator validators are supported
The validateView method calls configured
ErrorProcessors to process errors found in validation.
BinderFactory,
ControlAccessorFactory,
ErrorProcessor,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_BINDER_FACTORY_NAME |
protected org.springframework.validation.BindingResult |
errors
Validation Errors
|
protected int |
height |
protected org.springframework.context.MessageSource |
messageSource
message source for internationalization
|
protected int |
width |
| Constructor and Description |
|---|
ViewSupport()
Default ctor
|
ViewSupport(T model)
Create the view and set the model
|
| Modifier and Type | Method and Description |
|---|---|
void |
addControlChangeListener(ControlChangeListener l)
Add a ControlChangeListener to be notified on view changes.
|
void |
addError(org.springframework.validation.ObjectError error)
Add a binding error
|
void |
addView(View view)
Add a subview, the subview is refreshed, updated and hold the same model
that this view, for adding views with other models, use bind()
|
protected void |
afterRefresh()
Allow subclasses to do something after refresh
|
protected void |
afterUpdate()
Callback method on update()
|
void |
autobind()
Bind controls following the same name convention or annotated with Property annotation.
|
void |
bind(Object component,
String propertyName)
add a binding for control and model property name
|
void |
bind(Object component,
String propertyName,
boolean readOnly)
add a binding for control and model property name
|
protected void |
checkFactories() |
void |
clear()
Reset view state to default values
|
void |
controlChange(ControlEvent e)
Notify that the value of the control has changed
|
protected void |
doRefresh()
Allow subclasses to do custom refresh
|
protected void |
doUpdate()
Callback method on update()
|
void |
enableView(boolean enabled)
Enable/Disable All controls
|
protected void |
fireControlChange(ControlEvent e)
Notifiy Listeners that control value has changed
|
PropertyBinder |
getBinder(String propertyName)
Lookup for a binder by property name
|
BinderFactory |
getBinderFactory()
Gets the binder factory
|
org.springframework.validation.BindingResult |
getBindingResult()
Get binding result
|
ControlAccessorFactory |
getControlAccessorFactory() |
ControlInitializer |
getControlInitializer() |
String |
getErrorMessage()
Build a error message with all errors.
|
List<ErrorProcessor> |
getErrorProcessors() |
int |
getHeight() |
Set<String> |
getIgnoredProperties() |
protected String |
getMessage(org.springframework.context.MessageSourceResolvable msr)
I18n Support
|
protected String |
getMessage(String code)
I18n Support
|
protected String |
getMessage(String code,
Locale locale)
I18n Support, get messae from given locale
|
org.springframework.context.MessageSource |
getMessageSource() |
T |
getModel()
Gets model
|
String |
getName()
Gets the view name
|
abstract Object |
getPanel()
Gets the view Component
|
org.springframework.validation.Validator |
getValidator() |
int |
getWidth() |
void |
ignoreProperties(Collection<? extends String> c)
Add a Collection of property names to ignore on binding
|
void |
ignoreProperty(String propertyName)
Add a property name to ignore on binding.
|
boolean |
isDirty()
Check if user change any controls of view
|
boolean |
isInitializeControls() |
void |
listen(Object control)
Listen control for changes.
|
protected void |
onSetModel(T model)
Callback method to handle model changes
|
void |
refresh()
Update Component from model
|
void |
removeControlChangeListener(ControlChangeListener l)
Remove a previously added ControlChangeListener
|
void |
setBinderFactory(BinderFactory binderFactory)
Sets the binder factory, propagate it to composite binder.
|
void |
setControlAccessorFactory(ControlAccessorFactory controlAccessorFactory) |
void |
setControlInitializer(ControlInitializer controlInitializer) |
void |
setDirty(boolean dirty) |
void |
setErrorProcessors(List<ErrorProcessor> errorProcessors) |
void |
setHeight(int height) |
void |
setIgnoredProperties(Set<String> ignoredProperties) |
void |
setInitializeControls(boolean initializeControls) |
void |
setMessageSource(org.springframework.context.MessageSource messageSource) |
void |
setModel(T model)
Sets model
|
void |
setName(String name) |
void |
setValidator(org.springframework.validation.Validator validator) |
void |
setWidth(int width) |
void |
update()
Update Model from Component
|
boolean |
validateView()
validate model
|
public static final String DEFAULT_BINDER_FACTORY_NAME
@Autowired protected org.springframework.context.MessageSource messageSource
protected org.springframework.validation.BindingResult errors
protected int width
protected int height
public ViewSupport()
public ViewSupport(T model)
model - model to setpublic void bind(Object component, String propertyName, boolean readOnly)
component - controlpropertyName - the model property path to bindreadOnly - if true, binding only do refresh()protected void checkFactories()
public void bind(Object component, String propertyName)
component - controlpropertyName - the model property path to bindpublic abstract Object getPanel()
public T getModel()
getModel in interface ModelHolder<T>public final void setModel(T model)
setModel in interface ModelHolder<T>protected void onSetModel(T model)
model - the new modelpublic final void update()
protected void doUpdate()
protected void afterUpdate()
public void addView(View view)
view - public final void refresh()
protected void doRefresh()
protected void afterRefresh()
public void listen(Object control)
public void controlChange(ControlEvent e)
controlChange in interface ControlChangeListenere - ControlEvent with control change infopublic BinderFactory getBinderFactory()
public void setBinderFactory(BinderFactory binderFactory)
binderFactory - to setpublic boolean validateView()
validateView in interface View<T>public String getErrorMessage()
getErrorMessage in interface View<T>public void addError(org.springframework.validation.ObjectError error)
error - error to addpublic void clear()
public void enableView(boolean enabled)
enableView in interface View<T>public void autobind()
protected String getMessage(String code)
code - message codeprotected String getMessage(String code, Locale locale)
code - protected String getMessage(org.springframework.context.MessageSourceResolvable msr)
msr - message source resolvablepublic void addControlChangeListener(ControlChangeListener l)
ViewaddControlChangeListener in interface View<T>l - the ControlChangeListener to add.public void removeControlChangeListener(ControlChangeListener l)
ViewremoveControlChangeListener in interface View<T>l - ControlChangeListener to remove.protected void fireControlChange(ControlEvent e)
public void ignoreProperty(String propertyName)
propertyName - property name to ignorepublic void setIgnoredProperties(Set<String> ignoredProperties)
ignoredProperties - the ignoredProperties to setpublic void ignoreProperties(Collection<? extends String> c)
c - Collection of property names.public org.springframework.validation.Validator getValidator()
public void setValidator(org.springframework.validation.Validator validator)
validator - the validator to setpublic org.springframework.context.MessageSource getMessageSource()
public void setMessageSource(org.springframework.context.MessageSource messageSource)
messageSource - the messageSource to setpublic int getWidth()
public void setWidth(int width)
width - the width to setpublic int getHeight()
public void setHeight(int height)
height - the height to setpublic void setName(String name)
name - the name to setpublic List<ErrorProcessor> getErrorProcessors()
public void setErrorProcessors(List<ErrorProcessor> errorProcessors)
errorProcessors - the errorProcessors to setpublic boolean isDirty()
Viewpublic void setDirty(boolean dirty)
dirty - the dirty to setpublic ControlAccessorFactory getControlAccessorFactory()
public void setControlAccessorFactory(ControlAccessorFactory controlAccessorFactory)
controlAccessorFactory - the controlAccessorFactory to setpublic org.springframework.validation.BindingResult getBindingResult()
getBindingResult in interface Binder<T>public PropertyBinder getBinder(String propertyName)
getBinder in interface BinderHolderpropertyName - property namepublic boolean isInitializeControls()
public void setInitializeControls(boolean initializeControls)
initializeControls - the initializeControls to setpublic ControlInitializer getControlInitializer()
public void setControlInitializer(ControlInitializer controlInitializer)
controlInitializer - the controlInitializer to setCopyright © 2014 JDAL. All Rights Reserved.