我想在 JavaServer 页面上的表格中打印我的所有产品,但我的 jstl 代码有问题。
我的模型产品:
public final class Product
{
private int id;
private String description;
private Double price;
private String categoryName;
...
我的 JavaBean 产品:(创建此 bean 时,它填充了我模型中的产品)
@ManagedBean(name = "productsBean")
@RequestScoped
public class Products implements Serializable {
private List<Product> producten;
@ManagedProperty(value = "#{applicationBean}")
private ApplicationBean applicationBean;
public Producten() {
Store store = applicationBean.getStore();
for (String c : store.getCategories()) {
for(model.Product p : store.getProductsOfCategory(c)){
beans.Product product = new Product();
product.setId(p.getId());
product.setDescription(p.getDescription());
product.setCategoryName(p.getCategoryName());
product.setPrice(p.getPrice());
producten.add(product);
}
}
}
我的 JavaBean 产品:
@ManagedBean(name= "productBean")
@RequestScoped
public class Product implements Serializable{
@ManagedProperty(value = "#{applicationBean}")
private ApplicationBean applicationBean;
private int product_id;
private String description;
private Double price;
private String categoryName;
在我的 JavaServer Page 我想要这样的东西,但是:
<c:forEach var="product" items="${productsBean.products}">
<tr>
<td>${product.description}</td>
</tr>
</c:forEach>