I would fill datatable, but jsf does not show items in table, why? Thank you in advance who will be able to help me. I can't understand what's wrong with my code. My Java class in model
public class Product {
private int id;
private String name;
private float price;
public Product(int id, String name, float price) {
this.id = id;
this.name = name;
this.price = price;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public float getPrice() {
return price;
}
}
My ManagedBean:
@ManagedBean(name = "product")
@RequestScoped
public class DataTable implements Serializable {
private List<Product> productsList;
public List<Product> getProductsList() {
productsList = new ArrayList<>();
productsList.add(new Product(1,"HP Laptop",25000f));
productsList.add(new Product(2,"Dell Laptop",30000f));
productsList.add(new Product(3,"Lenevo Laptop",28000f));
productsList.add(new Product(4,"Sony Laptop",28000f));
productsList.add(new Product(5,"Apple Laptop",90000f));
return productsList;
}
}
My index.xhtml (I've tried to add "rows" attribute, but I have the same problem
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:body>
<h:form>
<h2>
<h:outputText value="Product List"></h:outputText>
</h2>
<h:dataTable value="#{product.productsList}" var="p">
<h:column>
<f:facet name="header">ID</f:facet>
<h:outputText value="#{p.id}" />
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="#{p.name}" />
</h:column>
<h:column>
<f:facet name="header">Price</f:facet>
<h:outputText value="#{p.price}" />
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
This is my result: