我无法显示包含多个类对象的表单错误,在我的例子中是 ProductMilestone。基本上,我在表格中显示了一个包含所有里程碑的表格,显示和更新效果很好。一旦出现错误,我的模板就无法再显示,并出现错误“[IllegalStateException: No value]”。这是因为错误的表单不包含从 Form.get() 方法接收到的值,在我的例子中是 MilestoneSet。我该怎么做才能使这项工作与显示的错误有关?
问题是视图中的for循环:
看法:
@(milestoneFormSet: Form[ProductMilestone.MilestoneSet], productReleaseId: Long) @*Function called by the for loop in the form just below*@ @milestoneFields(milestone: ProductMilestone, index: Integer) = { //…other fields @inputText(milestoneFormSet("milestoneList[" + index + "].initialDate"), '_label -> "",'class -> "datepicker") …} @form(routes.ProductMilestones.submitEdit(productReleaseId), 'id -> "submitMilestoneEditForm") { @*Here is the problem, when the form has an error I can not access milestoneList using get in the for loop*@ @for((milestone, index) <- milestoneFormSet.get.milestoneList.zipWithIndex) { @milestoneFields(milestone, index) } }
控制器:
public static Result submitEdit(Long productReleaseId) { Form<MilestoneSet> filledForm = form(MilestoneSet.class).bindFromRequest(); if (filledForm.hasErrors()) { return badRequest(views.html.milestonesEdit.render(filledForm, productReleaseId)); } else { MilestoneSet newMilestoneSet = filledForm.get(); //...update code }