Difference between DataBinder and ConversionService in Spring

I am experiencing some confusion about the use and purpose of Spring DataBinder and ConversionService regarding binding of web requests to object modeling. This arose because I recently tried using the JSR-303 check by adding.

Before that I used:

<bean
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="webBindingInitializer">
        <bean class="mypackage.GlobalWebBindingInitializer" />
    </property>
</bean>

This was good because I needed a global DataBinder that could be used by multiple controllers. The GlobalWebBindingInitialzer class implements several of them:

binder.registerCustomEditor(MyClass.class, new PropertyEditorSupport(MyClass.class)

However, I wanted to use the @Valid annotation and so added. A side effect of this is that the aforementioned AnnotationMethodHandlerAdapter bean is already defined as part of the annotation driven, so my global data binding is ignored.

So now I created this class:

public class MyClassConverter implements Converter<String, MyClass>

. , ?

+5
2

Spring javabeans. JavaBean PropertyEditors .

Spring 3.0 ​​ . "core.convert" "format", " PropertyEditors".

, , , , . , , .

, .

+3

PropertyEditors (esp PropertyEditorSupport) , -, . PropertyEditors .

, Spring PropertyEditors . , SpringMVC?

EDIT:

PropertyEditorSupport Spring . , initBinder() , . , , .

@InitBinder
public void initBinder(WebDataBinder binder) {

    logger.info("initBinder() called.");

    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
    dateFormat.setLenient(false);

    binder.registerCustomEditor(Date.class, new CustomDateEditor(
            dateFormat, false));
}

"initBinder()". , .

+1

All Articles