Example usage for org.springframework.core.convert ConversionException getMessage

List of usage examples for org.springframework.core.convert ConversionException getMessage

Introduction

In this page you can find the example usage for org.springframework.core.convert ConversionException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:de.interseroh.report.controller.ParameterFormConverter.java

public void convert(ParameterForm parameterForm, final Errors errors) {

    // Convert parameter values to required type
    parameterForm.accept(new AbstractParameterVisitor() {
        @Override//  w  w w.jav  a2s . c  o m
        public <V, T> void visit(ScalarParameter<V, T> parameter) {
            String name = parameter.getName();
            String propertyPath = ParameterUtils.nameToTextPath(name);
            Class<V> requiredType = parameter.getValueType();
            T textValue = parameter.getText();
            if (isConversionNeeded(requiredType, textValue)) {
                try {
                    DisplayFormatHolder.setDisplayFormat(parameter.getDisplayFormat());

                    V converted = conversionService.convert(textValue, requiredType);
                    parameter.setValue(converted);
                } catch (ConversionException ce) {
                    // TODO idueppe - here we need a more user friendly
                    // error code with parameters
                    errors.rejectValue(propertyPath, "conversion.error.unknown_format", ce.getMessage());
                }
            }
        }

        private <V, T> boolean isConversionNeeded(Class<V> requiredType, T textValue) {
            return textValue != null && conversionService.canConvert(textValue.getClass(), requiredType);
        }

    });
}