I have a dataTable that is populated using my Bean. I am only wanting to display the first 15 results, then allow the user to use a next button that will display the next 15 results. Here is my dataTable
<h:dataTable id ="data" value="#{copd.getCopds()}" var="c"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row">
my CopdBean has an int value called pageNumber that it passes down to be used with the CopdDaoImpl to determine the results for the table. Here is a quick path down the backend...
CopdBean.java
public List<Copd> getCopds(){
return copdBo.findAllCopd(pageNumber);
}
copdBoImp.java
public List<Copd> findAllCopd(int pageNumber) {
return copdDao.findAllCopd(pageNumber);
}
copdDaoImp.java
private static int pageSize = 15;
public List<Copd> findAllCopd(int pageNumber){
Criteria crit = getSession().createCriteria(Copd.class);
crit.add(Restrictions.like("copdPK.upi","0%"));
crit.addOrder(Order.desc("copdPK.upi"));
crit.setFirstResult(pageSize * (pageNumber -1));
crit.setMaxResults(pageSize);
return crit.list();
}
So as you can see, when the pageNumber int value is updated, the copd.getCopds() will display the next 15. When i hard code and change the int value to say 2, 3, or 4 and run the webapp, everything displays correclty. I'm just needing button functionality that will update this pageNumber value, and refresh the dataTable(aka recalling the copd.getCopds() and storing that result as 'value' in the dataTable.
I have a commandButton labeled Next that will call a method to update my pageNumber int value. But when this button is clicked nothing happens. I have even ran in debug and it seems the method is never called.
<h:commandButton value="Next" action="#{copd.nextPage()}"/>
copd.nextPage() just increases the int value by 1. However clicking this button does nothing. I have tried
onclick="refreshTable()"
with
<script type="text/javascript">
function refreshTable()
{
var table = document.getElementById("data");
table.refresh();
}
</script>
I have also tried <f:ajax render="data"/>
Everything works for my application, i'm just trying to basically update the 'value' in the dataTable and then refresh the dataTable without the whole page refreshing(which i'm told will then start over with a new bean) so that i'm only displaying 15 rows at a time vs. all 150 or 200 or 4000. Any help is greatly appreciated as I know its just something simple i'm missing on my front end dataTable.