name ppolishing
This commit is contained in:
@@ -131,17 +131,17 @@ public class DefaultValidationFailureMessageResolverFactory implements Validatio
|
||||
Map stringArgs = new HashMap();
|
||||
if (!stringArgs.containsKey(LABEL_ARGUMENT)) {
|
||||
String label;
|
||||
if (failure.getPropertyName() != null) {
|
||||
label = appendLabelPrefix().append(CODE_SEPARATOR).append(modelContext.getObjectName()).append(
|
||||
CODE_SEPARATOR).append(failure.getPropertyName()).toString();
|
||||
if (failure.getProperty() != null) {
|
||||
label = appendLabelPrefix().append(CODE_SEPARATOR).append(modelContext.getModel()).append(
|
||||
CODE_SEPARATOR).append(failure.getProperty()).toString();
|
||||
} 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
|
||||
.getPropertyName()));
|
||||
.getProperty()));
|
||||
}
|
||||
if (!stringArgs.containsKey(VALUE_ARGUMENT) && failure.getPropertyName() != null) {
|
||||
stringArgs.put(VALUE_ARGUMENT, modelContext.getInvalidUserValue());
|
||||
if (!stringArgs.containsKey(VALUE_ARGUMENT) && failure.getProperty() != null) {
|
||||
stringArgs.put(VALUE_ARGUMENT, modelContext.getInvalidValue());
|
||||
}
|
||||
if (failure.getArguments() != null) {
|
||||
Iterator it = failure.getArguments().entrySet().iterator();
|
||||
@@ -149,9 +149,9 @@ public class DefaultValidationFailureMessageResolverFactory implements Validatio
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Object arg = entry.getValue();
|
||||
if (!(arg instanceof String) && !(arg instanceof MessageSourceResolvable)) {
|
||||
if (modelContext.getPropertyTypeConverter() != null
|
||||
if (modelContext.getPropertyConverter() != null
|
||||
&& arg.getClass().equals(modelContext.getPropertyType())) {
|
||||
arg = conversionService.executeConversion(modelContext.getPropertyTypeConverter(), arg,
|
||||
arg = conversionService.executeConversion(modelContext.getPropertyConverter(), arg,
|
||||
String.class);
|
||||
} else {
|
||||
arg = conversionService.executeConversion(arg, String.class);
|
||||
@@ -161,15 +161,15 @@ public class DefaultValidationFailureMessageResolverFactory implements Validatio
|
||||
}
|
||||
}
|
||||
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() {
|
||||
String constraintMessageCode = appendMessageCodePrefix().append(CODE_SEPARATOR).append(
|
||||
failure.getConstraint()).toString();
|
||||
if (failure.getPropertyName() != null) {
|
||||
if (failure.getProperty() != null) {
|
||||
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();
|
||||
String typeConstraintMessageCode = appendMessageCodePrefix().append(CODE_SEPARATOR).append(
|
||||
modelContext.getPropertyType().getName()).append(CODE_SEPARATOR)
|
||||
@@ -177,7 +177,7 @@ public class DefaultValidationFailureMessageResolverFactory implements Validatio
|
||||
return new String[] { propertyConstraintMessageCode, typeConstraintMessageCode, constraintMessageCode };
|
||||
} else {
|
||||
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() };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ import org.springframework.binding.message.MessageContext;
|
||||
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.
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ValidationFailure {
|
||||
|
||||
private String propertyName;
|
||||
private String property;
|
||||
|
||||
private String constraint;
|
||||
|
||||
@@ -40,17 +40,16 @@ public class ValidationFailure {
|
||||
|
||||
/**
|
||||
* 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 severity the severity of the failure (required)
|
||||
* @param arguments named failure arguments (may be null)
|
||||
* @param defaultMessage the default message text (may be null)
|
||||
*/
|
||||
public ValidationFailure(String propertyName, String constraint, Severity severity, Map arguments,
|
||||
String defaultMessage) {
|
||||
public ValidationFailure(String property, String constraint, Severity severity, Map arguments, String defaultMessage) {
|
||||
Assert.hasText(constraint, "The constraint is required");
|
||||
Assert.notNull(severity, "The severity is required");
|
||||
this.propertyName = propertyName;
|
||||
this.property = property;
|
||||
this.constraint = constraint;
|
||||
this.severity = severity;
|
||||
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
|
||||
* object.
|
||||
*/
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
public String getProperty() {
|
||||
return property;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
*/
|
||||
public class ValidationFailureBuilder {
|
||||
|
||||
private String propertyName;
|
||||
private String property;
|
||||
|
||||
private String constraint;
|
||||
|
||||
@@ -45,11 +45,11 @@ public class ValidationFailureBuilder {
|
||||
|
||||
/**
|
||||
* Sets the property the failure occurred against.
|
||||
* @param propertyName the property name
|
||||
* @param property the property name
|
||||
* @return this, for fluent call chaining
|
||||
*/
|
||||
public ValidationFailureBuilder forProperty(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
public ValidationFailureBuilder forProperty(String property) {
|
||||
this.property = property;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ public class ValidationFailureBuilder {
|
||||
|
||||
/**
|
||||
* Adds a failure message argument.
|
||||
* @param name the arg name
|
||||
* @param value the arg value
|
||||
* @param name the argument name
|
||||
* @param value the argument value
|
||||
* @return this, for fluent call chaining
|
||||
*/
|
||||
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
|
||||
* itself needs to be localized.
|
||||
* @param name the arg name
|
||||
* @param code the code that will be used to resolve the arg
|
||||
* @param name the argument name
|
||||
* @param code the code that will be used to resolve the argument
|
||||
* @see MessageSourceResolvable
|
||||
* @return this, for fluent call chaining
|
||||
*/
|
||||
@@ -115,7 +115,7 @@ public class ValidationFailureBuilder {
|
||||
if (severity == null) {
|
||||
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 {
|
||||
|
||||
private String objectName;
|
||||
|
||||
private Class propertyType;
|
||||
|
||||
private String propertyTypeConverter;
|
||||
private String model;
|
||||
|
||||
private Object invalidValue;
|
||||
|
||||
private Class propertyType;
|
||||
|
||||
private String propertyConverter;
|
||||
|
||||
/**
|
||||
* 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 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,
|
||||
String propertyTypeConverter) {
|
||||
this.objectName = objectName;
|
||||
public ValidationFailureModelContext(String model, Object invalidValue, Class propertyType, String propertyConverter) {
|
||||
this.model = model;
|
||||
this.invalidValue = invalidValue;
|
||||
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() {
|
||||
return objectName;
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* The user entered value.
|
||||
* The invalid user entered value.
|
||||
*/
|
||||
public Object getInvalidUserValue() {
|
||||
public Object getInvalidValue() {
|
||||
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.
|
||||
*/
|
||||
public String getPropertyTypeConverter() {
|
||||
return propertyTypeConverter;
|
||||
public String getPropertyConverter() {
|
||||
return propertyConverter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user