org.springframework.binding.form.support
Class DefaultFormModel

java.lang.Object
  extended by org.springframework.binding.value.support.AbstractPropertyChangePublisher
      extended by org.springframework.binding.form.support.AbstractFormModel
          extended by org.springframework.binding.form.support.DefaultFormModel
All Implemented Interfaces:
ConfigurableFormModel, FormModel, HierarchicalFormModel, ValidatingFormModel, PropertyChangePublisher

public class DefaultFormModel
extends AbstractFormModel
implements ValidatingFormModel

Default form model implementation. Is configurable, hierarchical and validating.

If you need this form model to use validation rules that are specific to a given context (such as a specific form), then you will need to call setValidator(Validator) with a validator configured with the required context id. Like this: RulesValidator validator = myValidatingFormModel.getValidator(); validator.setRulesContextId( "mySpecialFormId" ); Along with this you will need to register your rules using the context id. See DefaultRulesSource.addRules(String, org.springframework.rules.Rules).

Author:
Keith Donald, Oliver Hutchison

Nested Class Summary
protected  class DefaultFormModel.ValidatingFormValueModel
           
 
Nested classes/interfaces inherited from class org.springframework.binding.form.support.AbstractFormModel
AbstractFormModel.ChildStateChangeHandler, AbstractFormModel.ConvertingValueModelKey, AbstractFormModel.ParentStateChangeHandler
 
Field Summary
 
Fields inherited from class org.springframework.binding.form.support.AbstractFormModel
childStateChangeHandler, parentStateChangeHandler
 
Fields inherited from class org.springframework.binding.value.support.AbstractPropertyChangePublisher
logger
 
Fields inherited from interface org.springframework.binding.form.ValidatingFormModel
VALIDATING_PROPERTY
 
Fields inherited from interface org.springframework.binding.form.FormModel
COMMITTABLE_PROPERTY, DIRTY_PROPERTY, ENABLED_PROPERTY, READONLY_PROPERTY
 
Constructor Summary
DefaultFormModel()
           
DefaultFormModel(MutablePropertyAccessStrategy domainObjectAccessStrategy)
           
DefaultFormModel(MutablePropertyAccessStrategy domainObjectAccessStrategy, boolean bufferChanges)
           
DefaultFormModel(Object domainObject)
           
DefaultFormModel(Object domainObject, boolean buffered)
           
DefaultFormModel(ValueModel domainObjectHolder)
           
DefaultFormModel(ValueModel domainObjectHolder, boolean buffered)
           
 
Method Summary
 void addChild(HierarchicalFormModel child)
          Add child to this FormModel.
protected  void childStateChanged(PropertyChangeEvent evt)
          Events from the child form model or value models that have side-effects on this form model should be handled here.
protected  void clearBindingError(DefaultFormModel.ValidatingFormValueModel valueModel)
           
 void clearValidationMessage(ValidationMessage validationMessage)
          Clear validation messages that are generated by a process separate from the standard Validator.
protected  void formPropertyValueChanged(String formProperty)
           
protected  ValidationMessage getBindingErrorMessage(String propertyName, Object valueBeingSet, Exception e)
           
 boolean getHasErrors()
          Does this ValidatingFormModel or any of its children contain errors?
 ValidationResultsModel getValidationResults()
          Returns the ValidationResultsModel which encapsulates the set of validation messages currently active against this form model.
 Validator getValidator()
          Get the validator that will be used to validate the form model.
protected  void hasErrorsUpdated()
           
protected  void init()
          Initialization of DefaultFormModel.
 boolean isCommittable()
          Returns true if the changes held by this form are able to be committed.
 boolean isValidating()
          Is this form model currently validating?
protected  void parentStateChanged(PropertyChangeEvent evt)
          Events from the parent form model that have side-effects on this form model should be handled here.
protected  void postProcessNewConvertingValueModel(String formProperty, Class targetClass, ValueModel valueModel)
          Provides a hook for subclasses to perform some processing after a new converting value model has been added to this form model.
protected  void postProcessNewValueModel(String formProperty, ValueModel valueModel)
          Provides a hook for subclasses to perform some processing after a new value model has been added to this form model.
protected  ValueModel preProcessNewConvertingValueModel(String formProperty, Class targetClass, ValueModel formValueModel)
          Provides a hook for subclasses to optionally decorate a new converting value model added to this form model.
protected  ValueModel preProcessNewValueModel(String formProperty, ValueModel formValueModel)
          Provides a hook for subclasses to optionally decorate a new value model added to this form model.
protected  void raiseBindingError(DefaultFormModel.ValidatingFormValueModel valueModel, Object valueBeingSet, Exception e)
           
 void raiseValidationMessage(ValidationMessage validationMessage)
          Provide validation messages that are generated by a process separate from the standard Validator.
 void removeChild(HierarchicalFormModel child)
          Remove a child FormModel.
 void removeParent()
          Remove the parent form model
 void setBindingErrorMessageProvider(BindingErrorMessageProvider bindingErrorMessageProvider)
           
 void setParent(HierarchicalFormModel parent)
          Sets the parent form model.
 void setValidating(boolean validating)
          Sets whether or not validation is currently enabled for this form model.
 void setValidator(Validator validator)
          Set the validator that will be used to validate the form model.
 String toString()
           
 void validate()
          Forces the form model to validate its self.
protected  void validateAfterPropertyChanged(String formProperty)
           
protected  void validatingUpdated()
           
 
Methods inherited from class org.springframework.binding.form.support.AbstractFormModel
add, add, add, addCommitListener, addMethod, addMethod, commit, committableUpdated, createConvertingValueModel, createValueModel, dirtyUpdated, enabledUpdated, getChildren, getConversionService, getDefaultInstanceClass, getFieldFace, getFieldFaceSource, getFieldMetadata, getFieldNames, getFormObject, getFormObjectHolder, getFormObjectPropertyAccessStrategy, getId, getParent, getPropertyAccessStrategy, getValueModel, getValueModel, handleSetNullFormObject, hasValueModel, isBuffered, isDirty, isEnabled, isReadOnly, postCommit, preCommit, prepareValueModel, readOnlyUpdated, registerPropertyConverter, removeCommitListener, reset, revert, setConversionService, setDefaultInstanceClass, setEnabled, setFieldFaceSource, setFormObject, setId, setReadOnly
 
Methods inherited from class org.springframework.binding.value.support.AbstractPropertyChangePublisher
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, firePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasChanged, hasChanged, hasChanged, hasChanged, hasChanged, hasChanged, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.binding.form.ConfigurableFormModel
add, add, add, addMethod, addMethod, setEnabled, setId, setReadOnly
 
Methods inherited from interface org.springframework.binding.form.HierarchicalFormModel
getChildren, getParent
 
Methods inherited from interface org.springframework.binding.form.FormModel
addCommitListener, commit, getFieldFace, getFieldMetadata, getFieldNames, getFormObject, getFormObjectHolder, getId, getValueModel, getValueModel, hasValueModel, isBuffered, isDirty, isEnabled, isReadOnly, registerPropertyConverter, removeCommitListener, reset, revert, setFormObject
 
Methods inherited from interface org.springframework.binding.value.PropertyChangePublisher
addPropertyChangeListener, addPropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

DefaultFormModel

public DefaultFormModel()

DefaultFormModel

public DefaultFormModel(Object domainObject)

DefaultFormModel

public DefaultFormModel(Object domainObject,
                        boolean buffered)

DefaultFormModel

public DefaultFormModel(ValueModel domainObjectHolder)

DefaultFormModel

public DefaultFormModel(ValueModel domainObjectHolder,
                        boolean buffered)

DefaultFormModel

public DefaultFormModel(MutablePropertyAccessStrategy domainObjectAccessStrategy)

DefaultFormModel

public DefaultFormModel(MutablePropertyAccessStrategy domainObjectAccessStrategy,
                        boolean bufferChanges)
Method Detail

init

protected void init()
Initialization of DefaultFormModel. Adds a listener on the Enabled property in order to switch validating state on or off. When disabling a formModel, no validation will happen.


isValidating

public boolean isValidating()
Is this form model currently validating?

Specified by:
isValidating in interface ValidatingFormModel

setValidating

public void setValidating(boolean validating)
Description copied from interface: ValidatingFormModel
Sets whether or not validation is currently enabled for this form model. If validation is enabled the form model will immediately validate all form properties. If validation is disabled all validation messages held by the ValidationResultsModel will be cleared.

Specified by:
setValidating in interface ValidatingFormModel

validatingUpdated

protected void validatingUpdated()

addChild

public void addChild(HierarchicalFormModel child)
Description copied from class: AbstractFormModel
Add child to this FormModel. Dirty and committable changes are forwarded to parent model.

Specified by:
addChild in interface HierarchicalFormModel
Overrides:
addChild in class AbstractFormModel
Parameters:
child - FormModel to add as child.

removeChild

public void removeChild(HierarchicalFormModel child)
Description copied from class: AbstractFormModel
Remove a child FormModel. Dirty and committable listeners are removed. When child was dirty, remove the formModel from the dirty list and update the dirty state.

Specified by:
removeChild in interface HierarchicalFormModel
Overrides:
removeChild in class AbstractFormModel
Parameters:
child - FormModel to remove from childlist.

childStateChanged

protected void childStateChanged(PropertyChangeEvent evt)
Events from the child form model or value models that have side-effects on this form model should be handled here. This includes: Note that we include value models and their metadata as being children. As these are low level models, they cannot be parents and therefore don't show up in AbstractFormModel.parentStateChanged(PropertyChangeEvent). Additionally the DefaultFormModel adds the event: Note that we see the ValidationResultsModel as a child model of the DefaultFormModel as the result model is bundled together with the value models.

Overrides:
childStateChanged in class AbstractFormModel

setParent

public void setParent(HierarchicalFormModel parent)
Description copied from interface: HierarchicalFormModel
Sets the parent form model.

Specified by:
setParent in interface HierarchicalFormModel
Overrides:
setParent in class AbstractFormModel

parentStateChanged

protected void parentStateChanged(PropertyChangeEvent evt)
Events from the parent form model that have side-effects on this form model should be handled here. This includes: Additionally the DefaultFormModel adds the event:

Overrides:
parentStateChanged in class AbstractFormModel

removeParent

public void removeParent()
Description copied from interface: HierarchicalFormModel
Remove the parent form model

Specified by:
removeParent in interface HierarchicalFormModel
Overrides:
removeParent in class AbstractFormModel

getValidationResults

public ValidationResultsModel getValidationResults()
Description copied from interface: ValidatingFormModel
Returns the ValidationResultsModel which encapsulates the set of validation messages currently active against this form model. Will be empty if validation is disabled.

Specified by:
getValidationResults in interface ValidatingFormModel

getHasErrors

public boolean getHasErrors()
Description copied from interface: ValidatingFormModel
Does this ValidatingFormModel or any of its children contain errors?

Specified by:
getHasErrors in interface ValidatingFormModel

hasErrorsUpdated

protected void hasErrorsUpdated()

validate

public void validate()
Description copied from interface: ValidatingFormModel
Forces the form model to validate its self. If validation is disabled it does nothing.

Specified by:
validate in interface ValidatingFormModel

getValidator

public Validator getValidator()
Description copied from interface: ValidatingFormModel
Get the validator that will be used to validate the form model.

Specified by:
getValidator in interface ValidatingFormModel

setValidator

public void setValidator(Validator validator)
Set the validator that will be used to validate the form model.

Setting a validator will trigger a validate of the current object.

Specified by:
setValidator in interface ValidatingFormModel

isCommittable

public boolean isCommittable()
Description copied from interface: FormModel
Returns true if the changes held by this form are able to be committed. A form is committable when it and it's child form models have no validation errors.

Specified by:
isCommittable in interface FormModel
Overrides:
isCommittable in class AbstractFormModel

preProcessNewValueModel

protected ValueModel preProcessNewValueModel(String formProperty,
                                             ValueModel formValueModel)
Description copied from class: AbstractFormModel
Provides a hook for subclasses to optionally decorate a new value model added to this form model.

Specified by:
preProcessNewValueModel in class AbstractFormModel

postProcessNewValueModel

protected void postProcessNewValueModel(String formProperty,
                                        ValueModel valueModel)
Description copied from class: AbstractFormModel
Provides a hook for subclasses to perform some processing after a new value model has been added to this form model.

Specified by:
postProcessNewValueModel in class AbstractFormModel

preProcessNewConvertingValueModel

protected ValueModel preProcessNewConvertingValueModel(String formProperty,
                                                       Class targetClass,
                                                       ValueModel formValueModel)
Description copied from class: AbstractFormModel
Provides a hook for subclasses to optionally decorate a new converting value model added to this form model.

Specified by:
preProcessNewConvertingValueModel in class AbstractFormModel

postProcessNewConvertingValueModel

protected void postProcessNewConvertingValueModel(String formProperty,
                                                  Class targetClass,
                                                  ValueModel valueModel)
Description copied from class: AbstractFormModel
Provides a hook for subclasses to perform some processing after a new converting value model has been added to this form model.

Specified by:
postProcessNewConvertingValueModel in class AbstractFormModel

formPropertyValueChanged

protected void formPropertyValueChanged(String formProperty)

validateAfterPropertyChanged

protected void validateAfterPropertyChanged(String formProperty)
Parameters:
formProperty - the name of the only property that has changed since the last call to validateAfterPropertyChange or null if this is not known/available.

raiseBindingError

protected void raiseBindingError(DefaultFormModel.ValidatingFormValueModel valueModel,
                                 Object valueBeingSet,
                                 Exception e)

clearBindingError

protected void clearBindingError(DefaultFormModel.ValidatingFormValueModel valueModel)

raiseValidationMessage

public void raiseValidationMessage(ValidationMessage validationMessage)
Description copied from interface: ValidatingFormModel
Provide validation messages that are generated by a process separate from the standard Validator.

All error messages that are raised using this method must be cleared using the method #cleanValdationMessage(ValidationMessage) before the form model can be commited.

Specified by:
raiseValidationMessage in interface ValidatingFormModel
Parameters:
validationMessage - the message to raise

clearValidationMessage

public void clearValidationMessage(ValidationMessage validationMessage)
Description copied from interface: ValidatingFormModel
Clear validation messages that are generated by a process separate from the standard Validator.

Specified by:
clearValidationMessage in interface ValidatingFormModel
Parameters:
validationMessage - the message to clear

getBindingErrorMessage

protected ValidationMessage getBindingErrorMessage(String propertyName,
                                                   Object valueBeingSet,
                                                   Exception e)

setBindingErrorMessageProvider

public void setBindingErrorMessageProvider(BindingErrorMessageProvider bindingErrorMessageProvider)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.