org.springframework.beans.PropertyAccessException Java Examples

The following examples show how to use org.springframework.beans.PropertyAccessException. 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: DefaultBindingErrorProcessor.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
}
 
Example #2
Source File: UifBindingErrorProcessor.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * 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"});
        }
    }
}
 
Example #3
Source File: DefaultBindingErrorProcessor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);
}
 
Example #4
Source File: DataBinder.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
		}
	}
}
 
Example #5
Source File: BeanUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example #6
Source File: ControlBindingErrorProcessor.java    From jdal with Apache License 2.0 5 votes vote down vote up
/** 
 * 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()));
}
 
Example #7
Source File: AbstractBinder.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example #8
Source File: AutoBinder.java    From jdal with Apache License 2.0 5 votes vote down vote up
public void execute(ControlAccessor controlAccessor, String name) {
	try {
		modelPropertyAccessor.setPropertyValue(name, controlAccessor.getControlValue());
	}
	catch (PropertyAccessException pae) { 
		errorProcessor.processPropertyAccessException(pae, bindingResult);
	}
}
 
Example #9
Source File: JseBindingErrorProcessor.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
/**
 * {@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);
    }
}
 
Example #10
Source File: DefaultBindingErrorProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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()));
}
 
Example #11
Source File: DataBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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());
		}
	}
}
 
Example #12
Source File: DefaultBindingErrorProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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()));
}
 
Example #13
Source File: DataBinder.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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());
		}
	}
}
 
Example #14
Source File: DataBinder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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());
		}
	}
}
 
Example #15
Source File: TypeOrFormatMismatchException.java    From sinavi-jfw with Apache License 2.0 4 votes vote down vote up
protected static String generateMessage(PropertyAccessException e, BindingResult binding) {
    PropertyEditingException ex = (PropertyEditingException) e.getCause();
    return ex.getMessage();
}
 
Example #16
Source File: BindingErrorProcessor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);
 
Example #17
Source File: BindingErrorProcessor.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
 
Example #18
Source File: TypeOrFormatMismatchException.java    From sinavi-jfw with Apache License 2.0 2 votes vote down vote up
/**
 * コンストラクタです。
 * @param e 例外
 * @param binding バインディング結果
 */
public TypeOrFormatMismatchException(PropertyAccessException e, BindingResult binding) {
    super(e.getPropertyChangeEvent(), generateMessage(e, binding), null);
    this.e = e;
}
 
Example #19
Source File: BindingErrorProcessor.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * 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);
 
Example #20
Source File: BindingErrorProcessor.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * 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);