Fix for bean validation messages in BindingResult
Previously Web Flow's BindingResult implementation distinguished object from field-level errors by checking if the source of the error is null or otherwise a String. However, class-level bean validation errors have a field source represented by an empty String. After this change object and field-level errors are recognized by checking for String-based field source that is neither null nor empty. This commit also contains a fix for spring-faces tests where in JSF 2.1 the presence of an unreleased FacesContext may cause some tests to fail.
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.binding.message;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* An object of communication that provides text information. For example, a validation message may inform a web
|
||||
@@ -49,7 +50,8 @@ public class Message implements Serializable {
|
||||
|
||||
/**
|
||||
* A reference to the source element this message is associated with. This could be a field on a form in UI, or null
|
||||
* if the message is not associated with a any particular element.
|
||||
* (or empty "" in the case of global bean validation) if the message is not associated with a any particular
|
||||
* element.
|
||||
* @return the source
|
||||
*/
|
||||
public Object getSource() {
|
||||
@@ -72,6 +74,18 @@ public class Message implements Serializable {
|
||||
return severity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the message is associated with a field.
|
||||
* @return {@code true} if the source is a String that has text; {@code false} otherwise.
|
||||
*/
|
||||
public boolean hasField() {
|
||||
if (this.source instanceof String) {
|
||||
return StringUtils.hasText((String) this.source);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("source", source).append("severity", severity).append("text", text)
|
||||
.toString();
|
||||
|
||||
Reference in New Issue
Block a user