Spring表单模型属性类与另一个对象

时间:2018-03-01 20:16:32

标签: forms spring-mvc model

我使用Spring MVC和JSP。我想使用表单输入类产品。类产品有另一个对象目录

产品类

public class Product {
    private int productId;
    private Catalog catalog;
    private String sku;
    private String productName;
    private int availableQuantity;
    private String uom;

    public Product() {

    }

目录是

public class Catalog {

 protected static Logger logger = Logger.getLogger(Catalog.class.getName());

private int catalogId;
private String catalogName;
private List<Product> products= new ArrayList<Product>();

public Catalog() {

}

我在控制器中创建了一个modelAttribute产品

model.addAttribute(new Product());
 return "product/addProduct";   

我想使用下拉列表输入目录ID。这个下拉列表是

<tr> 
            <th><label for="catalog_id">Catalog id:</label></th>
            <td><sf:select path="catalog" items="${catalogList}" />

            </td> 
        </tr> 

jsp是:

 <sf:form method="POST" modelAttribute="product">
<table border="0">
    <tr> 
        <th><label for="catalog_id">Catalog id:</label></th>
        <td><sf:select path="catalog" items="${catalogList}" />

        </td> 
    </tr> 

    <tr> 
        <th><label for="product_name">Product Name:</label></th>
        <td><sf:input path="productName" size="128" id="product_name" /><br/>
            <sf:errors path="productName" cssClass="error" /> 
        </td> 
    </tr> 
    <tr> 
        <th><label for="product_sku">Product sku:</label></th>
        <td><sf:input path="sku" size="32" id="product_sku" /><br/>
            <sf:errors path="sku" cssClass="error" /> 
        </td> 
    </tr> 
    <tr> 
        <th><label for="product_availablequantity">Available Quantity:</label></th>
        <td><sf:input path="availableQuantity"  id="product_availablequantity" /><br/>
            <sf:errors path="availableQuantity" cssClass="error" /> 
        </td> 
    </tr> 
    <tr> 
        <th><label for="product_unitofmeasure">Unit of measure:</label></th>
        <td><sf:input path="uom"  size="32"  id="product_unitofmeasure" /><br/>
            <sf:errors path="uom" cssClass="error" /> 
        </td> 
    </tr> 
    <tr>
        <th></th>
        <td><input type="submit" value="Save" /></td>
    </tr>
</table>
</sf:form>

</body>
</html>

如何定义路径product.catalog.catalogId?

0 个答案:

没有答案