Java Code Examples for org.springframework.validation.Errors#NESTED_PATH_SEPARATOR

The following examples show how to use org.springframework.validation.Errors#NESTED_PATH_SEPARATOR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringValidatorAdapter.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Return FieldError arguments for a validation error on the given field.
 * Invoked for each violated constraint.
 * <p>The default implementation returns a first argument indicating the field name
 * (of type DefaultMessageSourceResolvable, with "objectName.field" and "field" as codes).
 * Afterwards, it adds all actual constraint annotation attributes (i.e. excluding
 * "message", "groups" and "payload") in alphabetical order of their attribute names.
 * <p>Can be overridden to e.g. add further attributes from the constraint descriptor.
 * @param objectName the name of the target object
 * @param field the field that caused the binding error
 * @param descriptor the JSR-303 constraint descriptor
 * @return the Object array that represents the FieldError arguments
 * @see org.springframework.validation.FieldError#getArguments
 * @see org.springframework.context.support.DefaultMessageSourceResolvable
 * @see org.springframework.validation.DefaultBindingErrorProcessor#getArgumentsForBindError
 */
protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintDescriptor<?> descriptor) {
	List<Object> arguments = new LinkedList<Object>();
	String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field};
	arguments.add(new DefaultMessageSourceResolvable(codes, field));
	// Using a TreeMap for alphabetical ordering of attribute names
	Map<String, Object> attributesToExpose = new TreeMap<String, Object>();
	for (Map.Entry<String, Object> entry : descriptor.getAttributes().entrySet()) {
		String attributeName = entry.getKey();
		Object attributeValue = entry.getValue();
		if (!internalAnnotationAttributes.contains(attributeName)) {
			attributesToExpose.put(attributeName, attributeValue);
		}
	}
	arguments.addAll(attributesToExpose.values());
	return arguments.toArray(new Object[arguments.size()]);
}
 
Example 2
Source File: SpringValidatorAdapter.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Build a resolvable wrapper for the specified field, allowing to resolve the field's
 * name in a {@code MessageSource}.
 * <p>The default implementation returns a first argument indicating the field:
 * of type {@code DefaultMessageSourceResolvable}, with "objectName.field" and "field"
 * as codes, and with the plain field name as default message.
 * @param objectName the name of the target object
 * @param field the field that caused the binding error
 * @return a corresponding {@code MessageSourceResolvable} for the specified field
 * @since 4.3
 */
protected MessageSourceResolvable getResolvableField(String objectName, String field) {
	String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field};
	return new DefaultMessageSourceResolvable(codes, field);
}
 
Example 3
Source File: SpringValidatorAdapter.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Build a resolvable wrapper for the specified field, allowing to resolve the field's
 * name in a {@code MessageSource}.
 * <p>The default implementation returns a first argument indicating the field:
 * of type {@code DefaultMessageSourceResolvable}, with "objectName.field" and "field"
 * as codes, and with the plain field name as default message.
 * @param objectName the name of the target object
 * @param field the field that caused the binding error
 * @return a corresponding {@code MessageSourceResolvable} for the specified field
 * @since 4.3
 */
protected MessageSourceResolvable getResolvableField(String objectName, String field) {
	String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field};
	return new DefaultMessageSourceResolvable(codes, field);
}
 
Example 4
Source File: SpringValidatorAdapter.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Build a resolvable wrapper for the specified field, allowing to resolve the field's
 * name in a {@code MessageSource}.
 * <p>The default implementation returns a first argument indicating the field:
 * of type {@code DefaultMessageSourceResolvable}, with "objectName.field" and "field"
 * as codes, and with the plain field name as default message.
 * @param objectName the name of the target object
 * @param field the field that caused the binding error
 * @return a corresponding {@code MessageSourceResolvable} for the specified field
 * @since 4.3
 */
protected MessageSourceResolvable getResolvableField(String objectName, String field) {
	String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field};
	return new DefaultMessageSourceResolvable(codes, field);
}