Board index JavaServer Faces General Fire load method for LazyDataModel with Ajax

Fire load method for LazyDataModel with Ajax

Components, Ajax Framework, Utilities and More.


Posts: 9
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:

<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
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.


Posts: 315
Location: Brazil
Hi,

have you tried to call load in the handle method?


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
Graduando em Ciência da Computação - UFRGS


Primefaces 4.x, PF-Ext 1.x, Glassfish 4.x, JBossAS 7.1.2, Tomee, Mojarra: 2.1.x, CODI 1.0.5 on Ubuntu 12.04
Conventions Framework
Blog
@realpestano


Posts: 9
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.


Return to General