Java Code Examples for org.springframework.validation.FieldError#isBindingFailure()

The following examples show how to use org.springframework.validation.FieldError#isBindingFailure() . 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: EscapedErrors.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
private <T extends ObjectError> T escapeObjectError(@Nullable T source) {
	if (source == null) {
		return null;
	}
	String defaultMessage = source.getDefaultMessage();
	if (defaultMessage != null) {
		defaultMessage = HtmlUtils.htmlEscape(defaultMessage);
	}
	if (source instanceof FieldError) {
		FieldError fieldError = (FieldError) source;
		Object value = fieldError.getRejectedValue();
		if (value instanceof String) {
			value = HtmlUtils.htmlEscape((String) value);
		}
		return (T) new FieldError(
				fieldError.getObjectName(), fieldError.getField(), value, fieldError.isBindingFailure(),
				fieldError.getCodes(), fieldError.getArguments(), defaultMessage);
	}
	else {
		return (T) new ObjectError(
				source.getObjectName(), source.getCodes(), source.getArguments(), defaultMessage);
	}
}
 
Example 2
Source File: EscapedErrors.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
private <T extends ObjectError> T escapeObjectError(@Nullable T source) {
	if (source == null) {
		return null;
	}
	String defaultMessage = source.getDefaultMessage();
	if (defaultMessage != null) {
		defaultMessage = HtmlUtils.htmlEscape(defaultMessage);
	}
	if (source instanceof FieldError) {
		FieldError fieldError = (FieldError) source;
		Object value = fieldError.getRejectedValue();
		if (value instanceof String) {
			value = HtmlUtils.htmlEscape((String) value);
		}
		return (T) new FieldError(
				fieldError.getObjectName(), fieldError.getField(), value, fieldError.isBindingFailure(),
				fieldError.getCodes(), fieldError.getArguments(), defaultMessage);
	}
	else {
		return (T) new ObjectError(
				source.getObjectName(), source.getCodes(), source.getArguments(), defaultMessage);
	}
}
 
Example 3
Source File: EscapedErrors.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends ObjectError> T escapeObjectError(T source) {
	if (source == null) {
		return null;
	}
	if (source instanceof FieldError) {
		FieldError fieldError = (FieldError) source;
		Object value = fieldError.getRejectedValue();
		if (value instanceof String) {
			value = HtmlUtils.htmlEscape((String) value);
		}
		return (T) new FieldError(
				fieldError.getObjectName(), fieldError.getField(), value,
				fieldError.isBindingFailure(), fieldError.getCodes(),
				fieldError.getArguments(), HtmlUtils.htmlEscape(fieldError.getDefaultMessage()));
	}
	else {
		return (T) new ObjectError(
				source.getObjectName(), source.getCodes(), source.getArguments(),
				HtmlUtils.htmlEscape(source.getDefaultMessage()));
	}
}
 
Example 4
Source File: CustomValidatorFactoryBean.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
private boolean checkNoBindingFailure(Errors errors, String field) {
    FieldError error = errors.getFieldError(field);
    return error == null || !error.isBindingFailure();
}
 
Example 5
Source File: OriginTrackedFieldError.java    From spring-cloud-gray with Apache License 2.0 4 votes vote down vote up
private OriginTrackedFieldError(FieldError fieldError) {
    super(fieldError.getObjectName(), fieldError.getField(),
            fieldError.getRejectedValue(), fieldError.isBindingFailure(),
            fieldError.getCodes(), fieldError.getArguments(),
            fieldError.getDefaultMessage());
}
 
Example 6
Source File: EscapedErrors.java    From spring4-understanding with Apache License 2.0 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends ObjectError> T escapeObjectError(T source) {
	if (source == null) {
		return null;
	}
	if (source instanceof FieldError) {
		FieldError fieldError = (FieldError) source;
		Object value = fieldError.getRejectedValue();
		if (value instanceof String) {
			value = HtmlUtils.htmlEscape((String) value);
		}
		return (T) new FieldError(
				fieldError.getObjectName(), fieldError.getField(), value,
				fieldError.isBindingFailure(), fieldError.getCodes(),
				fieldError.getArguments(), HtmlUtils.htmlEscape(fieldError.getDefaultMessage()));
	}
	else {
		return (T) new ObjectError(
				source.getObjectName(), source.getCodes(), source.getArguments(),
				HtmlUtils.htmlEscape(source.getDefaultMessage()));
	}
}