Add a integer
property to your managed bean which gets size of list
private int sizeOfTable;
public int getSizeOfTable()
{
return customerBo.findAllCustomer().size();
}
public int setSizeOfTable(int sizeOfTable(int sizeOfTable)
{
this.sizeOfTable = sizeOfTable;
}
You can control the data table by rendered
attribute.
<h:dataTable value="#{customer.getCustomerList()}" var="c" rendered="#{customer.sizeOfTable == 0}"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
>
If the size of the data table is 0 then the data table will not be rendered. If you want to hide the header only you can add the rendered
value to h:column
However, Database rows are retreived for a single count operation. It is not a good practice. You should handle database accesses according to your needs. A database access is a IO operation for a computer which is the most costy part of operations.
My suggestion is to store the list in a data property and work on it.
private List<Customer> customerList;
public List<Customer> getCustomerList(){
if(customerList == null)
{
customerList = customerBo.findAllCustomer();
}
return customerList;
}
and you should edit your size property accordingly.
public int getSizeOfTable()
{
return customerList.size();
}