大家好我正在使用spring mvc并且我有一个表单,我必须在步骤中使用一个组合框驱动程序列表才能加载到组合框中但事实证明我将它显示为字符串而不是对象。
稍微高一点,我有一个组合框,我以相同的方式传递,但是在JSTL中没有形式和位置。
我需要的是我的对象的前两个属性是为组合框加载的
以下是代码和图片,以便他们可以帮助我。
控制器
@RequestMapping(value="products.htm", method=RequestMethod.GET)
public String homeSuppliers(@RequestParam(required=false) String state, ModelMap model){
try {
if (state != null) {
model.addAttribute("state", state);
}
List<ProveedoresDTO> listSupplier = supplierService.getAllSuppliersDTO();
List<ProductosDTO> listProducts = productService.getAllProductsDTO();
model.addAttribute("listProducts",listProducts);
model.addAttribute("listSupplier",listSupplier);
model.addAttribute("productAtt", new ProductsDTO());
} catch (Exception e) {
model.addAttribute("msg",e.getMessage());
}
return "productsView/products";
}
JSP
<select id="comboProducts" onchange="BuscaProductPorId()">
<option value="0"></option>
<c:forEach items="${listProducts}" var="product">
<option value="${product.productID}">${product.productName}</option>
</c:forEach>
</select>
<h1>${msg}</h1>
<form:form commandName="productAtt" action="crearProduct" method="get"
id="formSend">
<fieldset>
<legend>Product</legend>
<form:hidden path="productID" />
<table>
<tr>
<td><form:label path="productName">Nombre Product</form:label></td>
<td>:</td>
<td><form:input path="productName" /></td>
<td><form:errors path="productName" /></td>
</tr>
<tr>
<td><form:label path="supplierID">Select Supplier</form:label></td>
<td>:</td>
<td><form:select path="supplierID" multiple="false" items="${listSupplier}"></form:select></td>
<td><form:errors path="supplierID" /></td>
</tr>
<tr>
<td><form:label path="quantityPerUnit">Cantidad por Unidad</form:label></td>
<td>:</td>
<td><form:input path="quantityPerUnit" /></td>
<td><form:errors path="quantityPerUnit" /></td>
</tr>
<tr>
<td><form:label path="unitPrice">Precio Unitario</form:label></td>
<td>:</td>
<td><form:input path="unitPrice" /></td>
<td><form:errors path="unitPrice" /></td>
</tr>
<tr>
<td><form:label path="unitsInStock">Unidades en Stock</form:label></td>
<td>:</td>
<td><form:input path="unitsInStock" /></td>
<td><form:errors path="unitsInStock" /></td>
</tr>
<tr>
<td><form:label path="unitsOnOrder">Unidades en Orden</form:label></td>
<td>:</td>
<td><form:input path="unitsOnOrder" /></td>
<td><form:errors path="unitsOnOrder" /></td>
</tr>
<tr>
<td><form:label path="reorderLevel">Nivel de Orden</form:label></td>
<td>:</td>
<td><form:input path="reorderLevel" /></td>
<td><form:errors path="reorderLevel" /></td>
</tr>
<tr>
<td><form:label path="discontinued">Descontinuado</form:label></td>
<td>:</td>
<td><form:input path="discontinued" /></td>
<td><form:errors path="discontinued" /></td>
</tr>
<tr>
<td><br></td>
</tr>
<tr>
<td><input type="submit" value="Crear Product" name="crea"
id="crea"></td>
<td><input type="button" onclick="formReset()"
value="Limpiar Campos" /></td>
</tr>
</table>
</fieldset>
</form:form>
结果
答案 0 :(得分:4)
您没有指定要用于选项的内容。试试这个:
<form:select path="supplierID" multiple="false">
<form:options items="${listSupplier}" itemValue="SupplierID" itemLabel="CompanyName"/>
</form:select>
请注意,items
名称已更改为与@Controller