类org.springframework.beans.PropertyAccessException源码实例Demo

下面列出了怎么用org.springframework.beans.PropertyAccessException的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
	// Create field error with the exceptions's code, e.g. "typeMismatch".
	String field = ex.getPropertyName();
	Assert.state(field != null, "No field in exception");
	String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field);
	Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field);
	Object rejectedValue = ex.getValue();
	if (ObjectUtils.isArray(rejectedValue)) {
		rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue));
	}
	FieldError error = new FieldError(bindingResult.getObjectName(), field, rejectedValue, true,
			codes, arguments, ex.getLocalizedMessage());
	error.wrap(ex);
	bindingResult.addError(error);
}
 
@Override
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
	// Create field error with the exceptions's code, e.g. "typeMismatch".
	String field = ex.getPropertyName();
	Assert.state(field != null, "No field in exception");
	String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field);
	Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field);
	Object rejectedValue = ex.getValue();
	if (ObjectUtils.isArray(rejectedValue)) {
		rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue));
	}
	FieldError error = new FieldError(bindingResult.getObjectName(), field, rejectedValue, true,
			codes, arguments, ex.getLocalizedMessage());
	error.wrap(ex);
	bindingResult.addError(error);
}
 
源代码3 项目: rice   文件: UifBindingErrorProcessor.java
/**
 * Adds an entry to the {@link org.kuali.rice.krad.util.GlobalVariables#getMessageMap()} for the given
 * binding processing error
 *
 * @param ex exception that was thrown
 * @param bindingResult binding result containing the results of the binding process
 */
@Override
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
    // Create field error with the exceptions's code, e.g. "typeMismatch".
    super.processPropertyAccessException(ex, bindingResult);

    Object rejectedValue = ex.getValue();
    if (!(rejectedValue == null || rejectedValue.equals(""))) {
        if (ex.getCause() instanceof FormatException) {
            GlobalVariables.getMessageMap().putError(ex.getPropertyName(),
                    ((FormatException) ex.getCause()).getErrorKey(),
                    new String[] {rejectedValue.toString()});
        } else {
            GlobalVariables.getMessageMap().putError(ex.getPropertyName(), RiceKeyConstants.ERROR_CUSTOM,
                    new String[] {"Invalid format"});
        }
    }
}
 
源代码4 项目: spring-analysis-note   文件: DataBinder.java
/**
 * Apply given property values to the target object.
 * <p>Default implementation applies all of the supplied property
 * values as bean property values. By default, unknown fields will
 * be ignored.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getTarget
 * @see #getPropertyAccessor
 * @see #isIgnoreUnknownFields
 * @see #getBindingErrorProcessor
 * @see BindingErrorProcessor#processPropertyAccessException
 */
protected void applyPropertyValues(MutablePropertyValues mpvs) {
	try {
		// Bind request parameters onto target object.
		getPropertyAccessor().setPropertyValues(mpvs, isIgnoreUnknownFields(), isIgnoreInvalidFields());
	}
	catch (PropertyBatchUpdateException ex) {
		// Use bind error processor to create FieldErrors.
		for (PropertyAccessException pae : ex.getPropertyAccessExceptions()) {
			getBindingErrorProcessor().processPropertyAccessException(pae, getInternalBindingResult());
		}
	}
}
 
源代码5 项目: java-technology-stack   文件: DataBinder.java
/**
 * Apply given property values to the target object.
 * <p>Default implementation applies all of the supplied property
 * values as bean property values. By default, unknown fields will
 * be ignored.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getTarget
 * @see #getPropertyAccessor
 * @see #isIgnoreUnknownFields
 * @see #getBindingErrorProcessor
 * @see BindingErrorProcessor#processPropertyAccessException
 */
protected void applyPropertyValues(MutablePropertyValues mpvs) {
	try {
		// Bind request parameters onto target object.
		getPropertyAccessor().setPropertyValues(mpvs, isIgnoreUnknownFields(), isIgnoreInvalidFields());
	}
	catch (PropertyBatchUpdateException ex) {
		// Use bind error processor to create FieldErrors.
		for (PropertyAccessException pae : ex.getPropertyAccessExceptions()) {
			getBindingErrorProcessor().processPropertyAccessException(pae, getInternalBindingResult());
		}
	}
}
 
源代码6 项目: lams   文件: DefaultBindingErrorProcessor.java
@Override
public void processPropertyAccessException(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 FieldError(
			bindingResult.getObjectName(), field, rejectedValue, true,
			codes, arguments, ex.getLocalizedMessage()));
}
 
源代码7 项目: lams   文件: DataBinder.java
/**
 * Apply given property values to the target object.
 * <p>Default implementation applies all of the supplied property
 * values as bean property values. By default, unknown fields will
 * be ignored.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getTarget
 * @see #getPropertyAccessor
 * @see #isIgnoreUnknownFields
 * @see #getBindingErrorProcessor
 * @see BindingErrorProcessor#processPropertyAccessException
 */
protected void applyPropertyValues(MutablePropertyValues mpvs) {
	try {
		// Bind request parameters onto target object.
		getPropertyAccessor().setPropertyValues(mpvs, isIgnoreUnknownFields(), isIgnoreInvalidFields());
	}
	catch (PropertyBatchUpdateException ex) {
		// Use bind error processor to create FieldErrors.
		for (PropertyAccessException pae : ex.getPropertyAccessExceptions()) {
			getBindingErrorProcessor().processPropertyAccessException(pae, getInternalBindingResult());
		}
	}
}
 
@Override
public void processPropertyAccessException(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 FieldError(
			bindingResult.getObjectName(), field, rejectedValue, true,
			codes, arguments, ex.getLocalizedMessage()));
}
 
源代码9 项目: spring4-understanding   文件: DataBinder.java
/**
 * Apply given property values to the target object.
 * <p>Default implementation applies all of the supplied property
 * values as bean property values. By default, unknown fields will
 * be ignored.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getTarget
 * @see #getPropertyAccessor
 * @see #isIgnoreUnknownFields
 * @see #getBindingErrorProcessor
 * @see BindingErrorProcessor#processPropertyAccessException
 */
protected void applyPropertyValues(MutablePropertyValues mpvs) {
	try {
		// Bind request parameters onto target object.
		getPropertyAccessor().setPropertyValues(mpvs, isIgnoreUnknownFields(), isIgnoreInvalidFields());
	}
	catch (PropertyBatchUpdateException ex) {
		// Use bind error processor to create FieldErrors.
		for (PropertyAccessException pae : ex.getPropertyAccessExceptions()) {
			getBindingErrorProcessor().processPropertyAccessException(pae, getInternalBindingResult());
		}
	}
}
 
源代码10 项目: sinavi-jfw   文件: JseBindingErrorProcessor.java
/**
 * {@inheritDoc}
 */
@Override
public void processPropertyAccessException(PropertyAccessException e, BindingResult bindingResult) {

    TypeOrFormatMismatchException converted = null;
    if (Controllers.exceptionMatch(e.getCause().getClass(), PropertyEditingException.class)) {
        converted = new TypeOrFormatMismatchException(e, bindingResult);
        super.processPropertyAccessException(converted, bindingResult);
    } else {
        super.processPropertyAccessException(e, bindingResult);
    }
}
 
源代码11 项目: jdal   文件: AutoBinder.java
public void execute(ControlAccessor controlAccessor, String name) {
	try {
		modelPropertyAccessor.setPropertyValue(name, controlAccessor.getControlValue());
	}
	catch (PropertyAccessException pae) { 
		errorProcessor.processPropertyAccessException(pae, bindingResult);
	}
}
 
源代码12 项目: jdal   文件: AbstractBinder.java
/**
 * Set value on binded object using the property name.
 * @param value the value to set
 */
protected void setValue(Object value) {
	BeanWrapper wrapper = getBeanWrapper();
	Object convertedValue = convertIfNecessary(value, wrapper.getPropertyType(this.propertyName));
	try {
		wrapper.setPropertyValue(propertyName, convertedValue);
		oldValue = value;
	}
	catch (PropertyAccessException pae) {
		log.error(pae);
		errorProcessor.processPropertyAccessException(component, pae, bindingResult);
	}
}
 
源代码13 项目: jdal   文件: ControlBindingErrorProcessor.java
/** 
 * Add a ControlError instead FieldError to hold component that has failed.
 * @param control
 * @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()));
}
 
源代码14 项目: jdal   文件: BeanUtils.java
/**
 * Set property, without trowing exceptions on errors
 * @param bean bean name
 * @param name name
 * @param value value
 */
public static void setProperty(Object bean, String name, Object value) {
	try  {
		BeanWrapper wrapper = new BeanWrapperImpl(bean);
		wrapper.setPropertyValue(new PropertyValue(name, value));
	} catch (InvalidPropertyException ipe) {
		log.debug("Bean has no property: " + name);
	} catch (PropertyAccessException pae) {
		log.debug("Access Error on property: " + name);
	}
}
 
源代码15 项目: sinavi-jfw   文件: TypeOrFormatMismatchException.java
protected static String generateMessage(PropertyAccessException e, BindingResult binding) {
    PropertyEditingException ex = (PropertyEditingException) e.getCause();
    return ex.getMessage();
}
 
/**
 * Translate the given {@code PropertyAccessException} to an appropriate
 * error registered on the given {@code Errors} instance.
 * <p>Note that two error types are available: {@code FieldError} and
 * {@code ObjectError}. Usually, field errors are created, but in certain
 * situations one might want to create a global {@code ObjectError} instead.
 * @param ex the {@code PropertyAccessException} to translate
 * @param bindingResult the errors object to add the error(s) to.
 * You can add more than just one error or maybe even ignore it.
 * The {@code BindingResult} object features convenience utils such as
 * a {@code resolveMessageCodes} method to resolve an error code.
 * @see Errors
 * @see FieldError
 * @see ObjectError
 * @see MessageCodesResolver
 * @see BeanPropertyBindingResult#addError
 * @see BeanPropertyBindingResult#resolveMessageCodes
 */
void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult);
 
/**
 * Translate the given {@code PropertyAccessException} to an appropriate
 * error registered on the given {@code Errors} instance.
 * <p>Note that two error types are available: {@code FieldError} and
 * {@code ObjectError}. Usually, field errors are created, but in certain
 * situations one might want to create a global {@code ObjectError} instead.
 * @param ex the {@code PropertyAccessException} to translate
 * @param bindingResult the errors object to add the error(s) to.
 * You can add more than just one error or maybe even ignore it.
 * The {@code BindingResult} object features convenience utils such as
 * a {@code resolveMessageCodes} method to resolve an error code.
 * @see Errors
 * @see FieldError
 * @see ObjectError
 * @see MessageCodesResolver
 * @see BeanPropertyBindingResult#addError
 * @see BeanPropertyBindingResult#resolveMessageCodes
 */
void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult);
 
源代码18 项目: lams   文件: BindingErrorProcessor.java
/**
 * Translate the given {@code PropertyAccessException} to an appropriate
 * error registered on the given {@code Errors} instance.
 * <p>Note that two error types are available: {@code FieldError} and
 * {@code ObjectError}. Usually, field errors are created, but in certain
 * situations one might want to create a global {@code ObjectError} instead.
 * @param ex the {@code PropertyAccessException} to translate
 * @param bindingResult the errors object to add the error(s) to.
 * You can add more than just one error or maybe even ignore it.
 * The {@code BindingResult} object features convenience utils such as
 * a {@code resolveMessageCodes} method to resolve an error code.
 * @see Errors
 * @see FieldError
 * @see ObjectError
 * @see MessageCodesResolver
 * @see BeanPropertyBindingResult#addError
 * @see BeanPropertyBindingResult#resolveMessageCodes
 */
void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult);
 
/**
 * Translate the given {@code PropertyAccessException} to an appropriate
 * error registered on the given {@code Errors} instance.
 * <p>Note that two error types are available: {@code FieldError} and
 * {@code ObjectError}. Usually, field errors are created, but in certain
 * situations one might want to create a global {@code ObjectError} instead.
 * @param ex the {@code PropertyAccessException} to translate
 * @param bindingResult the errors object to add the error(s) to.
 * You can add more than just one error or maybe even ignore it.
 * The {@code BindingResult} object features convenience utils such as
 * a {@code resolveMessageCodes} method to resolve an error code.
 * @see Errors
 * @see FieldError
 * @see ObjectError
 * @see MessageCodesResolver
 * @see BeanPropertyBindingResult#addError
 * @see BeanPropertyBindingResult#resolveMessageCodes
 */
void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult);
 
源代码20 项目: sinavi-jfw   文件: TypeOrFormatMismatchException.java
/**
 * コンストラクタです。
 * @param e 例外
 * @param binding バインディング結果
 */
public TypeOrFormatMismatchException(PropertyAccessException e, BindingResult binding) {
    super(e.getPropertyChangeEvent(), generateMessage(e, binding), null);
    this.e = e;
}
 
 类方法
 同包方法