2011-07-09 55 views
0

我正在使用spring mvc portlet作为我的一个应用程序。在使用Controller中的List集合绑定动态填充列表框时遇到问题。spring portlet mvc form:select bind to 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列表框。

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

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

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

回答

0

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

春天MVC 3,请参阅下面的代码:

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

我们需要写一个TestPropertyEditor(延伸CustomCollectionEditor),这将有convertElement方法将字符串转换到一个合适的对象。

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