Custom property editors do not work for request parameters in Spring MVC?

Posted by dvd on Stack Overflow See other posts from Stack Overflow or by dvd
Published on 2010-06-08T15:26:29Z Indexed on 2010/06/08 17:43 UTC
Read the original article Hit count: 448


I'm trying to create a multiaction web controller using Spring annotations. This controller will be responsible for adding and removing user profiles and preparing reference data for the jsp page.

public class ManageProfilesController {
    public void initBinder(WebDataBinder binder) { 
        binder.registerCustomEditor(UserAccount.class,"account", new UserAccountPropertyEditor(userManager)); 
        binder.registerCustomEditor(Profile.class, "profile", new ProfilePropertyEditor(profileManager));"Editors registered");

    public void up( @RequestParam("account") UserAccount account,
                @RequestParam("profile") Profile profile) {

    public ModelAndView defaultView(@RequestParam("account") UserAccount account) {"Default view handling");
        ModelAndView mav = new ModelAndView();;
        mav.addObject("account", account);
        mav.addObject("profiles", profileManager.getProfiles());
        return mav;

Here is the part of my webContext.xml file:

<context:component-scan base-package="ru.mirea.rea.webapp.controllers" />
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">

<bean id="users.manageProfilesController" class="ru.mirea.rea.webapp.controllers.users.ManageProfilesController">
    <property name="view" value="home\users\manageProfiles"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

However, when i open the mapped url, i get exception:

java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [ru.mirea.rea.model.UserAccount]: no matching editors or conversion strategy found

I use spring 2.5.6 and plan to move to the Spring 3.0 in some not very distant future. However, according to this JIRA it should be possible already in spring 2.5.1.

The debug shows that the InitBinder method is correctly called.

What am i doing wrong?

© Stack Overflow or respective owner

Related posts about spring

Related posts about databinding