name ppolishing
This commit is contained in:
@@ -131,17 +131,17 @@ public class DefaultValidationFailureMessageResolverFactory implements Validatio
|
|||||||
Map stringArgs = new HashMap();
|
Map stringArgs = new HashMap();
|
||||||
if (!stringArgs.containsKey(LABEL_ARGUMENT)) {
|
if (!stringArgs.containsKey(LABEL_ARGUMENT)) {
|
||||||
String label;
|
String label;
|
||||||
if (failure.getPropertyName() != null) {
|
if (failure.getProperty() != null) {
|
||||||
label = appendLabelPrefix().append(CODE_SEPARATOR).append(modelContext.getObjectName()).append(
|
label = appendLabelPrefix().append(CODE_SEPARATOR).append(modelContext.getModel()).append(
|
||||||
CODE_SEPARATOR).append(failure.getPropertyName()).toString();
|
CODE_SEPARATOR).append(failure.getProperty()).toString();
|
||||||
} else {
|
} else {
|
||||||
label = appendLabelPrefix().append(CODE_SEPARATOR).append(modelContext.getObjectName()).toString();
|
label = appendLabelPrefix().append(CODE_SEPARATOR).append(modelContext.getModel()).toString();
|
||||||
}
|
}
|
||||||
stringArgs.put(LABEL_ARGUMENT, new DefaultMessageSourceResolvable(new String[] { label }, failure
|
stringArgs.put(LABEL_ARGUMENT, new DefaultMessageSourceResolvable(new String[] { label }, failure
|
||||||
.getPropertyName()));
|
.getProperty()));
|
||||||
}
|
}
|
||||||
if (!stringArgs.containsKey(VALUE_ARGUMENT) && failure.getPropertyName() != null) {
|
if (!stringArgs.containsKey(VALUE_ARGUMENT) && failure.getProperty() != null) {
|
||||||
stringArgs.put(VALUE_ARGUMENT, modelContext.getInvalidUserValue());
|
stringArgs.put(VALUE_ARGUMENT, modelContext.getInvalidValue());
|
||||||
}
|
}
|
||||||
if (failure.getArguments() != null) {
|
if (failure.getArguments() != null) {
|
||||||
Iterator it = failure.getArguments().entrySet().iterator();
|
Iterator it = failure.getArguments().entrySet().iterator();
|
||||||
@@ -149,9 +149,9 @@ public class DefaultValidationFailureMessageResolverFactory implements Validatio
|
|||||||
Map.Entry entry = (Map.Entry) it.next();
|
Map.Entry entry = (Map.Entry) it.next();
|
||||||
Object arg = entry.getValue();
|
Object arg = entry.getValue();
|
||||||
if (!(arg instanceof String) && !(arg instanceof MessageSourceResolvable)) {
|
if (!(arg instanceof String) && !(arg instanceof MessageSourceResolvable)) {
|
||||||
if (modelContext.getPropertyTypeConverter() != null
|
if (modelContext.getPropertyConverter() != null
|
||||||
&& arg.getClass().equals(modelContext.getPropertyType())) {
|
&& arg.getClass().equals(modelContext.getPropertyType())) {
|
||||||
arg = conversionService.executeConversion(modelContext.getPropertyTypeConverter(), arg,
|
arg = conversionService.executeConversion(modelContext.getPropertyConverter(), arg,
|
||||||
String.class);
|
String.class);
|
||||||
} else {
|
} else {
|
||||||
arg = conversionService.executeConversion(arg, String.class);
|
arg = conversionService.executeConversion(arg, String.class);
|
||||||
@@ -161,15 +161,15 @@ public class DefaultValidationFailureMessageResolverFactory implements Validatio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
text = (String) expression.getValue(new LazyMessageResolvingMap(messageSource, locale, stringArgs));
|
text = (String) expression.getValue(new LazyMessageResolvingMap(messageSource, locale, stringArgs));
|
||||||
return new Message(failure.getPropertyName(), text, failure.getSeverity());
|
return new Message(failure.getProperty(), text, failure.getSeverity());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] buildCodes() {
|
private String[] buildCodes() {
|
||||||
String constraintMessageCode = appendMessageCodePrefix().append(CODE_SEPARATOR).append(
|
String constraintMessageCode = appendMessageCodePrefix().append(CODE_SEPARATOR).append(
|
||||||
failure.getConstraint()).toString();
|
failure.getConstraint()).toString();
|
||||||
if (failure.getPropertyName() != null) {
|
if (failure.getProperty() != null) {
|
||||||
String propertyConstraintMessageCode = appendMessageCodePrefix().append(CODE_SEPARATOR).append(
|
String propertyConstraintMessageCode = appendMessageCodePrefix().append(CODE_SEPARATOR).append(
|
||||||
modelContext.getObjectName()).append(CODE_SEPARATOR).append(failure.getPropertyName()).append(
|
modelContext.getModel()).append(CODE_SEPARATOR).append(failure.getProperty()).append(
|
||||||
CODE_SEPARATOR).append(failure.getConstraint()).toString();
|
CODE_SEPARATOR).append(failure.getConstraint()).toString();
|
||||||
String typeConstraintMessageCode = appendMessageCodePrefix().append(CODE_SEPARATOR).append(
|
String typeConstraintMessageCode = appendMessageCodePrefix().append(CODE_SEPARATOR).append(
|
||||||
modelContext.getPropertyType().getName()).append(CODE_SEPARATOR)
|
modelContext.getPropertyType().getName()).append(CODE_SEPARATOR)
|
||||||
@@ -177,7 +177,7 @@ public class DefaultValidationFailureMessageResolverFactory implements Validatio
|
|||||||
return new String[] { propertyConstraintMessageCode, typeConstraintMessageCode, constraintMessageCode };
|
return new String[] { propertyConstraintMessageCode, typeConstraintMessageCode, constraintMessageCode };
|
||||||
} else {
|
} else {
|
||||||
String objectConstraintMessageCode = appendMessageCodePrefix().append(CODE_SEPARATOR).append(
|
String objectConstraintMessageCode = appendMessageCodePrefix().append(CODE_SEPARATOR).append(
|
||||||
modelContext.getObjectName()).append(CODE_SEPARATOR).append(failure.getConstraint()).toString();
|
modelContext.getModel()).append(CODE_SEPARATOR).append(failure.getConstraint()).toString();
|
||||||
return new String[] { objectConstraintMessageCode, failure.getConstraint() };
|
return new String[] { objectConstraintMessageCode, failure.getConstraint() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ import org.springframework.binding.message.MessageContext;
|
|||||||
public interface ValidationContext {
|
public interface ValidationContext {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The the name of the object being validated.
|
* The the name of the model object being validated.
|
||||||
*/
|
*/
|
||||||
public String getObjectName();
|
public String getModel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current user.
|
* The current user.
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public class ValidationFailure {
|
public class ValidationFailure {
|
||||||
|
|
||||||
private String propertyName;
|
private String property;
|
||||||
|
|
||||||
private String constraint;
|
private String constraint;
|
||||||
|
|
||||||
@@ -40,17 +40,16 @@ public class ValidationFailure {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new validation failure
|
* Creates a new validation failure
|
||||||
* @param propertyName the property that failed to validate (may be null to indicate a general failure)
|
* @param property the property that failed to validate (may be null to indicate a general failure)
|
||||||
* @param constraint the name of the validation constraint that failed (required)
|
* @param constraint the name of the validation constraint that failed (required)
|
||||||
* @param severity the severity of the failure (required)
|
* @param severity the severity of the failure (required)
|
||||||
* @param arguments named failure arguments (may be null)
|
* @param arguments named failure arguments (may be null)
|
||||||
* @param defaultMessage the default message text (may be null)
|
* @param defaultMessage the default message text (may be null)
|
||||||
*/
|
*/
|
||||||
public ValidationFailure(String propertyName, String constraint, Severity severity, Map arguments,
|
public ValidationFailure(String property, String constraint, Severity severity, Map arguments, String defaultMessage) {
|
||||||
String defaultMessage) {
|
|
||||||
Assert.hasText(constraint, "The constraint is required");
|
Assert.hasText(constraint, "The constraint is required");
|
||||||
Assert.notNull(severity, "The severity is required");
|
Assert.notNull(severity, "The severity is required");
|
||||||
this.propertyName = propertyName;
|
this.property = property;
|
||||||
this.constraint = constraint;
|
this.constraint = constraint;
|
||||||
this.severity = severity;
|
this.severity = severity;
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
@@ -61,8 +60,8 @@ public class ValidationFailure {
|
|||||||
* The name of the property that failed to validate. May be null to indicate a general failure against the validated
|
* The name of the property that failed to validate. May be null to indicate a general failure against the validated
|
||||||
* object.
|
* object.
|
||||||
*/
|
*/
|
||||||
public String getPropertyName() {
|
public String getProperty() {
|
||||||
return propertyName;
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import org.springframework.context.support.DefaultMessageSourceResolvable;
|
|||||||
*/
|
*/
|
||||||
public class ValidationFailureBuilder {
|
public class ValidationFailureBuilder {
|
||||||
|
|
||||||
private String propertyName;
|
private String property;
|
||||||
|
|
||||||
private String constraint;
|
private String constraint;
|
||||||
|
|
||||||
@@ -45,11 +45,11 @@ public class ValidationFailureBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the property the failure occurred against.
|
* Sets the property the failure occurred against.
|
||||||
* @param propertyName the property name
|
* @param property the property name
|
||||||
* @return this, for fluent call chaining
|
* @return this, for fluent call chaining
|
||||||
*/
|
*/
|
||||||
public ValidationFailureBuilder forProperty(String propertyName) {
|
public ValidationFailureBuilder forProperty(String property) {
|
||||||
this.propertyName = propertyName;
|
this.property = property;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,8 +83,8 @@ public class ValidationFailureBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a failure message argument.
|
* Adds a failure message argument.
|
||||||
* @param name the arg name
|
* @param name the argument name
|
||||||
* @param value the arg value
|
* @param value the argument value
|
||||||
* @return this, for fluent call chaining
|
* @return this, for fluent call chaining
|
||||||
*/
|
*/
|
||||||
public ValidationFailureBuilder arg(String name, Object value) {
|
public ValidationFailureBuilder arg(String name, Object value) {
|
||||||
@@ -98,8 +98,8 @@ public class ValidationFailureBuilder {
|
|||||||
/**
|
/**
|
||||||
* Adds a failure message argument whose value is also message source resolvable. Use this when the argument value
|
* Adds a failure message argument whose value is also message source resolvable. Use this when the argument value
|
||||||
* itself needs to be localized.
|
* itself needs to be localized.
|
||||||
* @param name the arg name
|
* @param name the argument name
|
||||||
* @param code the code that will be used to resolve the arg
|
* @param code the code that will be used to resolve the argument
|
||||||
* @see MessageSourceResolvable
|
* @see MessageSourceResolvable
|
||||||
* @return this, for fluent call chaining
|
* @return this, for fluent call chaining
|
||||||
*/
|
*/
|
||||||
@@ -115,7 +115,7 @@ public class ValidationFailureBuilder {
|
|||||||
if (severity == null) {
|
if (severity == null) {
|
||||||
severity = Severity.ERROR;
|
severity = Severity.ERROR;
|
||||||
}
|
}
|
||||||
return new ValidationFailure(propertyName, constraint, severity, args, defaultText);
|
return new ValidationFailure(property, constraint, severity, args, defaultText);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,40 +21,39 @@ package org.springframework.binding.validation;
|
|||||||
*/
|
*/
|
||||||
public class ValidationFailureModelContext {
|
public class ValidationFailureModelContext {
|
||||||
|
|
||||||
private String objectName;
|
private String model;
|
||||||
|
|
||||||
private Class propertyType;
|
|
||||||
|
|
||||||
private String propertyTypeConverter;
|
|
||||||
|
|
||||||
private Object invalidValue;
|
private Object invalidValue;
|
||||||
|
|
||||||
|
private Class propertyType;
|
||||||
|
|
||||||
|
private String propertyConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new validation model context.
|
* Creates a new validation model context.
|
||||||
* @param objectName the object name
|
* @param model the name of the model object that was validated
|
||||||
* @param invalidValue the invalid value the user entered
|
* @param invalidValue the invalid value the user entered
|
||||||
* @param propertyType the type of the property that failed to validate (may be null)
|
* @param propertyType the type of the property that failed to validate (may be null)
|
||||||
* @param propertyTypeConverter the id of the custom converter configured to format the property value (may be null)
|
* @param propertyConverter the id of the custom converter configured to format the property value (may be null)
|
||||||
*/
|
*/
|
||||||
public ValidationFailureModelContext(String objectName, Object invalidValue, Class propertyType,
|
public ValidationFailureModelContext(String model, Object invalidValue, Class propertyType, String propertyConverter) {
|
||||||
String propertyTypeConverter) {
|
this.model = model;
|
||||||
this.objectName = objectName;
|
|
||||||
this.invalidValue = invalidValue;
|
this.invalidValue = invalidValue;
|
||||||
this.propertyType = propertyType;
|
this.propertyType = propertyType;
|
||||||
this.propertyTypeConverter = propertyTypeConverter;
|
this.propertyConverter = propertyConverter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the object being validated.
|
* The name of the model object that was validated.
|
||||||
*/
|
*/
|
||||||
public String getObjectName() {
|
public String getModel() {
|
||||||
return objectName;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user entered value.
|
* The invalid user entered value.
|
||||||
*/
|
*/
|
||||||
public Object getInvalidUserValue() {
|
public Object getInvalidValue() {
|
||||||
return invalidValue;
|
return invalidValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,8 +67,8 @@ public class ValidationFailureModelContext {
|
|||||||
/**
|
/**
|
||||||
* When reporting a property validation failure, the id of the custom converter used to format the UI display value.
|
* When reporting a property validation failure, the id of the custom converter used to format the UI display value.
|
||||||
*/
|
*/
|
||||||
public String getPropertyTypeConverter() {
|
public String getPropertyConverter() {
|
||||||
return propertyTypeConverter;
|
return propertyConverter;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class DefaultValidationContext implements ValidationContext {
|
|||||||
this.mappingResults = mappingResults;
|
this.mappingResults = mappingResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getObjectName() {
|
public String getModel() {
|
||||||
// TODO
|
// TODO
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user