spring portlet mvc form:select bind to list

时间:2011-07-09 17:36:11

标签: spring select binding portlet

我正在为我的一个应用程序使用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列表数据填充从另一个列表框中选择的数据,并移至scheduledParticipants列表框。

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

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

有谁知道如何实现这个目标?

1 个答案:

答案 0 :(得分:0)

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

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

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

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

有关initBinder ....

的变体,请参阅Spring MVC框架参考文档
相关问题