Example usage for org.springframework.beans PropertyAccessException getErrorCode

List of usage examples for org.springframework.beans PropertyAccessException getErrorCode

Introduction

In this page you can find the example usage for org.springframework.beans PropertyAccessException getErrorCode.

Prototype

public abstract String getErrorCode();

Source Link

Document

Return a corresponding error code for this type of exception.

Usage

From source file:org.jdal.ui.bind.ControlBindingErrorProcessor.java

/** 
 * Add a ControlError instead FieldError to hold component that has failed.
 * @param control//from  w  w w  . j a v a 2  s .  c o m
 * @param ex
 * @param bindingResult
 */
public void processPropertyAccessException(Object control, PropertyAccessException ex,
        BindingResult bindingResult) {
    // Create field error with the exceptions's code, e.g. "typeMismatch".
    String field = ex.getPropertyName();
    String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field);
    Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field);
    Object rejectedValue = ex.getValue();
    if (rejectedValue != null && rejectedValue.getClass().isArray()) {
        rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue));
    }
    bindingResult.addError(new ControlError(control, bindingResult.getObjectName(), field, rejectedValue, true,
            codes, arguments, ex.getLocalizedMessage()));
}