我認爲我的語法是正確的,但我的表單支持對象中的列表沒有被填充。它看起來像列表本身正在制定,只是它沒有元素。其他屬性正在按預期填充。有任何想法嗎?Spring 3綁定對象到列表
JSP:
<form:form method="post" commandName="addReminder">
Reminder Name <input type='text' name='reminderName' placeholder="Reminder Name"> <br />
Date <input type='text' name='date' placeholder="1/05/2013"> <br />
Time <input type='text' name='time' placeholder="4:00 PM"> <br />
Time Zone <input type='text' name='timeZone' placeholder="EDT"> <br />
<br />
Contacts <input type='text' path="contacts[0].phoneNumber" placeholder="Name"> <br />
<input type='text' path="contacts[1].phoneNumber" placeholder="Name"> <br />
<input type="submit" value = "Add Reminder">
</form:form>
控制器:
@RequestMapping(value = "/AddAReminder", method = RequestMethod.POST)
public String addReminder(@ModelAttribute("addReminder") AddReminder reminder, BindingResult result)
{
//does stuff with the data from the form backing object
return "Add A Reminder";
}
表背襯對象:
public class AddReminder
{
private String reminderName;
private String date;
private String time;
private String timeZone;
private ArrayList<Contact> contacts = new ArrayList<Contact>();
private String sentFrom;
private String message;
private String provider;
//getters and setters
聯繫對象:
public class Contact
{
private String firstName;
private String lastName;
private String phoneNumber;
private String provider;
//getters and setters
好吧,我想出了我做了什麼改變,得到了這個工作。我使用GET請求上的Contact對象初始化列表。我說initalize,但我的意思是我只是添加一個元素到列表中,所以它不是空的。該列表本身已經在AddReminder類中初始化。 Spring將自動增加列表。 – 2013-04-28 22:09:36