0

I have a list products with these attributes :

  • Identifier
  • Color
  • Size
  • Supplier

Supplier attribute is an object that has these attributes :

  • Name
  • Phone

For each product in my list, i'd like to display the identifier & the supplier name. How can i do this with struts / jstl ?

Here is what i'm trying with no success :

<s:iterator value="products">
    <tr>
        <td><s:property value="identifiant"/></td>
        <td><s:property value="supplier.name"</td>
    </tr>
</s:iterator>
4

3 回答 3

2

每个属性都应该有吸气剂。如果productsAction类的属性,那么它应该有

//default constructor

public List<Product> getPoducts(){...} //getter

Product课堂上

//default constructor

public String getIdentifier(){...} //getter
public String getColor(){...} //getter
public String getPhone(){...} //getter
public String getSupplier(){...} //getter

Supplier课堂上

//default constructor

public String getName(){...} //getter
public String getPhone(){...} //getter

在 JSP 中

<s:iterator value="products">
    <tr>
        <td><s:property value="identifier"/></td>
        <td><s:property value="supplier.name"/></td>
    </tr>
</s:iterator>
于 2016-02-18T17:39:09.247 回答
0

使用 JSTL,您可以尝试<c:forEach>像这样使用标签:

<tr>
<c:forEach items="products" var="product>
    <td>
        <c:out value="${product.identifiant}">
        <c:out value="${product.supplier.name}">
    </td>
</c:forEach>
</tr>
于 2016-02-18T17:31:57.017 回答
0

你可以试试这个:

<c:forEach items="${products}" var="product">
    <tr>
        <td><c:out value="${product.identifier}" /></td>
        <td><c:out value="${product.supplier.name}" /></td>
    </tr>
</c:forEach>
于 2016-02-18T17:32:57.797 回答