【问题标题】:spring portlet mvc form:select bind to listspring portlet mvc 表单:选择绑定到列表
【发布时间】:2011-07-09 17:36:11
【问题描述】:

我正在为我的一个应用程序使用 spring mvc portlet。我在将动态填充的列表框与 Controller 中的 List 集合绑定时遇到问题。

Conference.java:

public class Conference {
    private List<Patient> scheduledPatients;
    //getter/setter for scheduledPatients
}

saveParticipants.jsp

<form:select path="scheduledParticipants" items="${scheduledParticipants}" itemLabel="name" itemValue="name" />

scheduledParticipants 列表数据填充了从另一个列表框中选择的数据并移动到 scheduleParticipants 列表框。

在提交操作请求时,我无法在控制器操作映射中绑定新填充的 scheduleParticipants。 ModelAttribute 是 Conference pojo。

我们使用 InitBinder 将数据绑定到 scheduleParticipants。 我仍然无法在控制器上获取选定的参与者数据。

有谁知道如何做到这一点?

【问题讨论】:

    标签: spring select binding portlet


    【解决方案1】:

    我们必须使用initBinder 将对象列表绑定到对应的bean。

    对于 Spring MVC 3,请参见以下代码:

    @InitBinder<br/>
    public void setTestBinder(WebDataBinder dataBinder) {
       dataBinder.registerCustomEditor(List.class, new TestPropertyEditor(List.class, true));
    }
    

    我们需要编写一个TestPropertyEditor(扩展CustomCollectionEditor),它将有一个convertElement 方法将字符串转换为适当的对象。

    有关initBinder....的变体,请参阅 Spring MVC 框架参考文档

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 2010-10-16
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多