jsf - Data Table header visible during page load even if there is no data to display -
i'm working on application spring, jsf, hibernate following example in this link.
when run code values populated in database, should have datatable header name along rows retrieved. when there no value in database , when run code, shouldn't display datatable header name. datatable header name should displayed when there values retrieved database , not during startup. how do this?
add integer
property managed bean 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 data table 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 size of data table 0 data table not rendered. if want hide header can add rendered
value h:column
however, database rows retreived single count operation. not practice. should handle database accesses according needs. database access io operation computer costy part of operations.
my suggestion store list in data property , work on it.
private list<customer> customerlist; public list<customer> getcustomerlist(){ if(customerlist == null) { customerlist = customerbo.findallcustomer(); } return customerlist; }
and should edit size property accordingly.
public int getsizeoftable() { return customerlist.size(); }
Comments
Post a Comment