Revision: 1714 http://svn.sourceforge.net/spring-rich-c/?rev=1714&view=rev Author: jhoskens Date: 2007-02-13 00:46:09 -0800 (Tue, 13 Feb 2007)
Log Message: ----------- currently the validationResultsModel is based on one FormModel. This may lead to errors when using childFormModels. To temporarily fix some of the issues, a getHasErrors() is provided on the ValidationFormModel which will check childFormModels and this is used in the FormGuard. In the future the parent-child relation should be revised and all side-effects should be taken into account. This includes validation/dirty/enabling... Modified Paths: -------------- trunk/spring-richclient/binding/src/main/java/org/springframework/binding/form/ValidatingFormModel.java trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/DefaultFormModel.java trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/FormGuard.java Modified: trunk/spring-richclient/binding/src/main/java/org/springframework/binding/form/ValidatingFormModel.java =================================================================== --- trunk/spring-richclient/binding/src/main/java/org/springframework/binding/form/ValidatingFormModel.java 2007-02-12 12:54:03 UTC (rev 1713) +++ trunk/spring-richclient/binding/src/main/java/org/springframework/binding/form/ValidatingFormModel.java 2007-02-13 08:46:09 UTC (rev 1714) @@ -20,24 +20,34 @@ import org.springframework.binding.validation.Validator; /** - * Sub-interface implemented by form models that can validatate the form's + * Sub-interface implemented by form models that can validatate the form's * properties. * * @author Keith Donald * @author Oliver Hutchison */ public interface ValidatingFormModel extends ConfigurableFormModel, HierarchicalFormModel { - + public static final String VALIDATING_PROPERTY = "validating"; - + /** - * Returns the ValidationResultsModel which encapsulates the set of + * Returns the ValidationResultsModel which encapsulates the set of * validation messages currently active against this form model. Will * be empty if validation is disabled. */ ValidationResultsModel getValidationResults(); - + /** + * Does this ValidatingFormModel contain errors? + * + * TODO validationResults aren't linked to childFormModel's results. This + * leads to incorrect behaviour. Should be revised. (getValidationResults() + * method above returns results of this model only while this method should + * cover all including children) + */ + boolean getHasErrors(); + + /** * Is this form model currently validating */ boolean isValidating(); @@ -52,11 +62,11 @@ void setValidating(boolean validating); /** - * Forces the form model to validate its self. If validation is disabled - * does nothing. + * Forces the form model to validate its self. If validation is disabled + * does nothing. */ public void validate(); - + /** * Get the validator that will be used to validate the form model. * @return validator @@ -78,13 +88,13 @@ * can be commited. * @param validationMessage the message to raise */ - void raiseValidationMessage(ValidationMessage validationMessage); + void raiseValidationMessage(ValidationMessage validationMessage); /** * Clear validation messages that are generated by * a process separate from the standard Validator. * @param validationMessage the message to clear */ - void clearValidationMessage(ValidationMessage validationMessage); + void clearValidationMessage(ValidationMessage validationMessage); } \ No newline at end of file Modified: trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/DefaultFormModel.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/DefaultFormModel.java 2007-02-12 12:54:03 UTC (rev 1713) +++ trunk/spring-richclient/support/src/main/java/org/springframework/binding/form/support/DefaultFormModel.java 2007-02-13 08:46:09 UTC (rev 1714) @@ -22,6 +22,7 @@ import org.springframework.binding.MutablePropertyAccessStrategy; import org.springframework.binding.form.BindingErrorMessageProvider; +import org.springframework.binding.form.FormModel; import org.springframework.binding.form.ValidatingFormModel; import org.springframework.binding.validation.RichValidator; import org.springframework.binding.validation.ValidationMessage; @@ -151,6 +152,22 @@ return validationResultsModel; } + public boolean getHasErrors() { + if (validationResultsModel.getHasErrors()) + return true; + + FormModel[] children = getChildren(); + for (int i = 0; i < children.length;++i) + { + if (children[i] instanceof ValidatingFormModel) + { + if (((ValidatingFormModel)children[i]).getHasErrors()) + return true; + } + } + return false; + } + public void validate() { if (isValidating()) { validateAfterPropertyChanged(null); Modified: trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/FormGuard.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/FormGuard.java 2007-02-12 12:54:03 UTC (rev 1713) +++ trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/FormGuard.java 2007-02-13 08:46:09 UTC (rev 1714) @@ -137,7 +137,7 @@ private int getFormModelState() { int formState = 0; - if (!formModel.getValidationResults().getHasErrors()) + if (!formModel.getHasErrors()) formState += ON_NOERRORS; if (formModel.isDirty()) formState += ON_ISDIRTY; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ spring-rich-c-cvs mailing list spring-rich-c-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs