1

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.

Aritz
  • 30,971
  • 16
  • 136
  • 217
  • First, you should not have a business logic method in your `getCopds` method because it can be called multiple times. Second, your managed bean should have `@ViewScoped` annotation in order to handle requests from the same view. Third, the `` should have the `` inside in order to update the content of your ``, and also it should render a component where you display the actual page number. – Luiggi Mendoza Jan 29 '13 at 23:02
  • I added the @ViewScoped annotation, the f:ajax was in the correct spot. I still have nothing working. The first suggestion I'm not 100% sure what to do because this is my first time working with java and beans. – LivinTheDream86 Jan 30 '13 at 15:14
  • took out the @ViewScoped. I wrapped everthing in my with a
    and my dataTable with a with respected id tags. made it work. thanks for all the help
    – LivinTheDream86 Jan 30 '13 at 16:53
  • Your problem was that you didn't have a `` that wrapped your ``. Please read: [h:commandLink / h:commandButton is not being invoked](http://stackoverflow.com/q/2118656/1065197). Next time, it would be good if you show more of your code, since this syntom wasn't easy to *guess* from your code. – Luiggi Mendoza Jan 30 '13 at 16:56

0 Answers0