Spring MVC中的CustomBinder用于处理对象列表

时间:2013-05-03 13:43:50

标签: spring-mvc

我有spring mvc表单,我提交了一个cusomized对象的值A.自定义对象A的一个字段作为另一个对象B的列表。

在控制器中,我可以看到对象B列表的大小,但它正在抛出错误消息 无法将类型'java.lang.String'的属性值转换为必需类型'java.util.List'

现在我已经创建了一个跟随

的类CustomBinder
public class CustomBinder extends PropertyEditorSupport {

    private List<b> listOfb;

    public CustomBinder(List<b> listOfb){
        this.listOfb = listOfb;
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        // TODO Auto-generated method stub
        setValue(listOfb);
    }

    @Override
    public String getAsText() {
    // TODO Auto-generated method stub
        return super.getAsText();
    }
}

在控制器中,我已经注册了custombinder

@InitBinder
protected void initBinder(Object target, WebDataBinder binder)
{
    binder.setValidator(this.productUniqueValidator);
    A a = (A) target;
    List<B> b= a.getLstOfB;
    binder.registerCustomEditor(List.class,"bs" ,new CustomBinder(b));
}

我仍然收到错误消息......不确定我做错了什么!!

0 个答案:

没有答案