Revision: 1356
http://svn.sourceforge.net/spring-rich-c/?rev=1356&view=rev
Author: jhoskens
Date: 2006-08-31 00:46:55 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
Added clearMessages method
Added check on previous Object Type: Form supports different Types
of objects (only requirement is having the needed properties).
RulesValidator wasn't taking this into account which leads to messages
that apply to another type to be mixed with messages that apply to the
type currently used in the form.
Modified Paths:
--------------
trunk/spring-richclient/support/src/main/java/org/springframework/binding/validation/DefaultValidationResults.java
trunk/spring-richclient/support/src/main/java/org/springframework/binding/validation/support/RulesValidator.java
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/binding/validation/DefaultValidationResults.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/binding/validation/DefaultValidationResults.java
2006-08-31 07:41:53 UTC (rev 1355)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/binding/validation/DefaultValidationResults.java
2006-08-31 07:46:55 UTC (rev 1356)
@@ -21,6 +21,7 @@
import java.util.Iterator;
import java.util.Set;
+import org.springframework.binding.validation.support.RulesValidator;
import org.springframework.core.style.ToStringCreator;
import org.springframework.util.CachingMapDecorator;
import org.springframework.util.ObjectUtils;
@@ -35,7 +36,7 @@
Set messagesSubSet = new HashSet();
for (Iterator i = messages.iterator(); i.hasNext();) {
ValidationMessage message = (ValidationMessage)i.next();
- if (key instanceof Severity &&
message.getSeverity().equals((Severity)key)) {
+ if (key instanceof Severity &&
message.getSeverity().equals(key)) {
messagesSubSet.add(message);
}
else if (ObjectUtils.nullSafeEquals(message.getProperty(),
key)) {
@@ -122,5 +123,16 @@
public String toString() {
return new ToStringCreator(this).append("messages",
getMessages()).toString();
}
+
+ /**
+ * Clear all messages.
+ *
+ * @see RulesValidator#clearMessages()
+ */
+ public void clearMessages()
+ {
+ messages.clear();
+ messagesSubSets.clear();
+ }
}
\ No newline at end of file
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/binding/validation/support/RulesValidator.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/binding/validation/support/RulesValidator.java
2006-08-31 07:41:53 UTC (rev 1355)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/binding/validation/support/RulesValidator.java
2006-08-31 07:46:55 UTC (rev 1356)
@@ -58,6 +58,8 @@
private String rulesContextId = null;
+ private Class objectClass;
+
/**
* Creates a RulesValidator for the given formModel. When no RulesSource is
* given, a default/global RulesSource is retrieved by the
ApplicationServices class.
@@ -85,6 +87,13 @@
}
public ValidationResults validate(Object object, String propertyName) {
+ // Forms can have different types of objects, so when type of object
+ // changes, messages that are already listed on the previous type must
+ // be removed.
+ if (objectClass != null && objectClass != object.getClass()) {
+ clearMessages();
+ }
+ objectClass = object.getClass();
Rules rules = null;
if (object instanceof PropertyConstraintProvider) {
PropertyConstraint validationRule =
((PropertyConstraintProvider)object).getPropertyConstraint(propertyName);
@@ -94,7 +103,7 @@
}
else {
if (getRulesSource() != null) {
- rules = getRulesSource().getRules(object.getClass(),
getRulesContextId());
+ rules = getRulesSource().getRules(objectClass,
getRulesContextId());
if (rules != null) {
for (Iterator i = rules.iterator(); i.hasNext();) {
PropertyConstraint validationRule =
(PropertyConstraint)i.next();
@@ -190,4 +199,15 @@
public String resolveObjectName(String objectName) {
return formModel.getFieldFace(objectName).getDisplayName();
}
+
+ /**
+ * Clear the current validationMessages and the errors.
+ *
+ * @see #validate(Object, String)
+ */
+ public void clearMessages()
+ {
+ this.results.clearMessages();
+ this.validationErrors.clear();
+ }
}
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs