我很努力地在JSP中獲取已更改的列表值以返回到MVC控制器。值顯示正常,但在提交表單時(在提交時顯示更改的任何非列表值),更改不會顯示在ModelAttribute中。下面是相關代碼的縮寫版本:Spring MVC列表值返回不變
JSP:
<c:forEach items="${poForm.poDetail}" varStatus="i">
...
<!-- Product Description -->
<td class="leftAlign" >
<form:input path="poDetail[${i.index}].description" />
</td>
打底FORM:
public class POForm {
private List<PurchaseOrderDetail> poDetail;
...
}
PURCHASEORDERDETAIL:
public class PurchaseOrderDetail implements Comparable<PurchaseOrderDetail>{
private String partNumber; // alpha-numeric part number (vendor's)
private String description; // Product name/description
... remaining properties are non-complex
}
控制器:
@RequestMapping(value="/savePO",method=RequestMethod.POST)
public ModelAndView savePO(@ModelAttribute("poForm") POForm poForm, final
HttpServletRequest request) {
.... "examine the poForm here and items of poDetail are unchanged"
}
任何建議嘗試?
您是否擁有poDetail和description屬性的setter和getter? – xyz
是的。我沒有將它們包含在代碼中以保持簡單。 – Mike
在這個控制器中是否有任何其他的@ModelAttribute註釋方法 - 它必須從某個地方檢索舊值 –