Fire load method for LazyDataModel with Ajax

Components, Ajax Framework, Utilities and More.
Post Reply
User avatar
bluefoot
Posts: 9
Joined: 02 Oct 2010, 15:27

13 Mar 2011, 17:46

Hi. Similar question was already asked here, but with no responses.
What I have is a calendar and a lazy DataTable. When a date is selected, the DataTable should call the method load of its LazyDataModel. But this is not happening. Here's the code:

In view:

Code: Select all

<p:calendar mode="inline" value="#{myMB.date }" onSelectUpdate="table" selectListener="#{myMB.handle}"  rowsPerPageTemplate="5,10,15"/>
<p:dataTable id="table" var="car" value="#{myMB.lazyModel}" paginator="true" rows="10" lazy="true">
  <p:column> 
    <h:outputText value="#{car} />
  </p:column>
</p:dataTable>
In MyMB

Code: Select all

public void handle(DateSelectEvent event) {
    setDate(event.getDate()); //no need, but let it here for now
}

public LazyDataModel<Car> getLazyModel() {
    loadModel();
    return lazyModel;
}

private void loadModel() {
    if (lazyModel == null) {
        lazyModel = new LazyDataModel<Car>() {
            @Override
            public List<Car> load(int first, int pageSize,
                    String sortField, boolean sortOrder,
                    Map<String, String> filters) {
                return mYMethodThatDOESReturnSomething(pageSize, first);
            }
        };

        lazyModel.setRowCount(10);//just for text
    }
}
See that rowsPerPageTemplate? ok, if I change the page (5, 10 or 15) in the dropdown, the load() method is called and the DataTable shows the results.

User avatar
kwintesencja
Posts: 316
Joined: 08 Feb 2010, 20:33
Location: Brazil

13 Mar 2011, 18:12

Hi,

have you tried to call load in the handle method?

Code: Select all

public void handle(DateSelectEvent event) {
    setDate(event.getDate()); //no need, but let it here for now
    DataTable lazyTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("formId:table");
     lazyTable.loadLazyData();
}
maybe it helps.
Att,

--

Rafael Mauricio Pestano


Primefaces 5.x + JavaEE7(Glassfish 4.x and Wildfly 8)
Conventions Framework
Blog
@realpestano

User avatar
bluefoot
Posts: 9
Joined: 02 Oct 2010, 15:27

13 Mar 2011, 18:20

True, it helps indeed. Thanks.
But this is not the most elegant-automatic way to do it, right? And this is not view-only dependent.

Well, I believe is the best I have so far.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests