我正在显示一个ProductList,它由Product对象组成。 Product具有int,string,string和int类型的属性。数据从数据库中提取,我构建了一个ProductList。数据在数据库中,我可以看到它,但是当我显示表时,表显示2个int列的0,以及String列中的空白。这是ProductList:
@ManagedBean
公共类ProductList {
private ArrayList<Product> allProducts;
public ProductList(){
allProducts = DatabaseConnector.getAllProducts();
}
public ArrayList<Product> getAllProducts(){
return allProducts;
}
public void setAllProducts(ArrayList<Product> allProducts){
this.allProducts = allProducts;
}
}
这是Product bean:
@ManagedBean
公共类产品{
private int id;
private String productName;
private String description;
private int quantity;
public Product() {
}
public void setId(int id) {
this.id = id;
}
public void setProductName(String productName) {
this.productName = productName;
}
public void setDescription(String description) {
this.description = description;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public int getId() {
return id;
}
public String getProductName() {
return productName;
}
public String getDescription() {
return description;
}
public int getQuantity() {
return quantity;
}
}
我应该更改bean的范围吗?
答案 0 :(得分:1)
向bean添加范围注释,例如@RequestScoped
或@ViewScoped
否则它将是@NoneScoped