2016-11-09 65 views
0

我想有一個列表,每一個記錄/行的表格單元格中的下拉列表JSTL形式:選擇在表格單元格中C:的forEach

customerList保持連接實體(與customerGroup和assignedVendor屬性)

vendorList持有供應商實體(有姓名和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

春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>