user1154644
user1154644

Reputation: 4609

backing bean in jsf scope

I am displaying a ProductList, which is made up of Product objects. The Product has attributes of type int, string, string, and int. The data is being pulled from the database and I build a 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. Here is the ProductList:

@ManagedBean

public class 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:

@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?

Upvotes: 0

Views: 121

Answers (1)

Daniel
Daniel

Reputation: 37051

Add scope annotation to your bean , for example @RequestScoped or @ViewScoped

otherwise it will be the default scope which is @NoneScoped

Upvotes: 1

Related Questions