首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不调用/调用InitBinder

不调用/调用InitBinder
EN

Stack Overflow用户
提问于 2013-08-29 04:55:22
回答 2查看 1.9K关注 0票数 0

我在JSP页面上有单选按钮。

代码语言:javascript
复制
<form:form  modelAttribute="obj" action="save">
    <form:radiobuttons path="person" items="${List}"/>

<form:button>Save</form:button>
</form:form>

List : person Obj:

代码语言:javascript
复制
Class obj{
     Person person;
     getter/setters
}

在那个JSP中,当选择特定的单选按钮时,我必须附加person。

在控制器侧

代码语言:javascript
复制
    @RequestMapping(value = "/save", method = RequestMethod.POST)
        public String postProcess(@ModelAttribute("obj") Obj obj,BindingResult error) {

            //processing
            return "anotherJsp";
        }


     @InitBinder
     public void initBinder(WebDataBinder binder, Locale locale, HttpServletRequest request) {
    binder.registerCustomEditor(Obj.class,"person", new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) {
            //processing for conversion of person object String to Person Object
            setValue(text);
        }
    });
}

这里我使用initbinder,因为我从jsp...So获得person对象字符串,所以我得到了绑定异常,它不能从字符串转换为Person

以前,当将数据绑定到InitBinder中的initbinder时,我将将字符串传递给Person对象。

这里的主要问题是我的InitBinder中没有调用/调用。请给我解决办法。

谢谢。

EN

回答 2

Stack Overflow用户

发布于 2013-08-29 05:04:13

请通过放置断点或调试语句检查它是否正在被调用。

您的模型属性名为"obj“。但是在propertyeditor中,您使用了"person“作为属性路径。

请尝试使用"obj“作为propertyPath或删除该参数并使用此签名。registerCustomEditor( requiredType类,PropertyEditor propertyEditor)

希望能帮上忙。

票数 2
EN

Stack Overflow用户

发布于 2013-10-16 14:48:03

在黑暗中狂野刺伤,它从org.springframework.web.bind.annotation导入正确的org.springframework.web.bind.annotation吗?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18502560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档