我希望列表中的每个记录/行的表格单元格中都有一个下拉列表
customerList保存Connection实体(具有customerGroup和assignedVendor属性)
vendorList保存供应商实体(具有name和customerID属性
这是我到目前为止所做的:
<form:form action="${pageContext.request.contextPath}/vendorAdmin/viewClients/${vendorGroupID}" method="post" >
<table class="table table-striped table-bordered table-hover " id="sample_1">
<thead>
<tr class="bg-success">
<th>Admin Name</th>
<th>Email</th>
<th>Username</th>
<th>Phone</th>
<th>Assign To</th>
<th></th>
</tr>
</thead>
<c:forEach items="${customerList}" var="connection" varStatus="cStatus">
<tr>
<td>${customerList[cStatus.index].customerGroup.name}</td>
<td class="text-center">${customerList[cStatus.index].customerGroup.customerList[0].email}</td>
<td class="text-center">${customerList[cStatus.index].customerGroup.customerList[0].username}</td>
<td class="text-center">${customerList[cStatus.index].customerGroup.customerList[0].phone}</td>
<td>
<form:select path="customerList[${cStatus.index}].assignedVendor.customerID">
<form:options items="${vendorList}" itemLabel="name" itemValue="customerID"/>
</form:select>
</td>
<td>
<a href="<spring:url value="/vendorAdmin/sendMessageToCustomer/${vendorGroupID}/${customerList[cStatus.index].customerGroup.userGroupID}" />"
><span class="glyphicon glyphicon-message "></span></a>
</td>
</tr>
</c:forEach>
</table>
</form:form>
错误:
ERROR o.s.web.servlet.tags.form.SelectTag - Neither BindingResult nor plain target object for bean name 'command' available as request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:141)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:132)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:116)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422)
at org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:194)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
有人可以指出我哪里出错吗?
编辑:我为不够清楚而道歉。问题不在于我无法从控制器获取customerList。一切正常,除了form:select
感觉就像我在path
犯了一个错误,无法访问该字段。希望这能让它更清晰
答案 0 :(得分:0)
Spring tablib需要一个命令名或模型属性,它可以绑定输入值。
让我们说你有这样的课 -
User{
private String name;
//Add getters setters
}
来自加载页面的控制器
@RequestMapping("/form")
public String getFormPage(Model model){
model.addAttribute("user",new User());
}
然后在form.jsp
中<form:form modelAttribute="user">/*user is set in model attribute in controller*/
<form:input path="name" placeholder="Input name">
</form:form>