[英]backing bean in jsf scope
I am displaying a ProductList, which is made up of Product objects. 我正在显示一个ProductList,它由Product对象组成。 The Product has attributes of type int, string, string, and int. 产品具有类型为int,string,string和int的属性。 The data is being pulled from the database and I build a ProductList. 数据正在从数据库中提取,我建立了一个ProductList。 The data is in the database, I can see it, but when I display the table, the table shows 0's for the 2 int columns, and blanks in the String columns. 数据在数据库中,可以看到它,但是当我显示该表时,该表在2个int列中显示0,在String列中显示空白。 Here is the ProductList: 这是产品列表:
@ManagedBean
public class ProductList { 公共类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;
}
} }
And here is the Product bean: 这是Product Bean:
@ManagedBean
public class Product { 公共类产品{
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;
}
} }
Should I change the scope of the beans? 我应该改变豆子的范围吗?
Add scope annotation to your bean , for example @RequestScoped
or @ViewScoped
将范围注释添加到您的bean中,例如@RequestScoped
或@ViewScoped
otherwise it will be the default scope which is @NoneScoped
否则它将是默认范围@NoneScoped
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.