7

I happen not to understand why my load method is not called in a lazydatamodel of my primefaces table. My xhtml page goes like this

<h:form id="myForm">
    <p:dataTable value="#{myBean.configDataModel}"
                            id="configTable" var="config" paginator="true" rows="10"
                            selectionMode="single"
                            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                            rowsPerPageTemplate="5,10,20">
    .
    .
</h:form>

My Bean code goes like this and put up system.out.println statements but I notice it isn't called.

public class MyBean{
    // private List<MyBean> configList;
    private LazyDataModel<MyBean> configDataModel;

    @SuppressWarnings("serial")
    public LazyDataModel<MyBean> getConfigDataModel() {
        if (configDataModel == null) {
            configDataModel = new LazyDataModel<MyBean>() {

                @Override
                public List<MyBean> load(int arg0, int arg1, String arg2,
                        SortOrder arg3, Map<String, String> arg4) {
                    System.out.println("Here!!!!!");
                    return null;
                }
            };

        }
        return configDataModel;
    }
    public void setConfigDataModel(LazyDataModel<MyBean> configDataModel) {
        this.configDataModel = configDataModel;
    }
}

What could be the cause?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mark Estrada
  • 9,013
  • 37
  • 119
  • 186

2 Answers2

25

Since PrimeFaces 3.3, you'd need to explicitly set the lazy attribute of the repeating component to true in order to enable the support for LazyDataModel.

<p:dataTable ... lazy="true">

See also:

Cœur
  • 37,241
  • 25
  • 195
  • 267
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Arrrrgggghh...So thats the reason, I have built a small app that uses lazydatamodel using Primefaces 3.1. I was just following along when I encounter this in the latest 3.4 build.. Thanks as always BalusC.. – Mark Estrada Nov 06 '12 at 02:48
  • I keep hitting my head with this one..... spend 15 minutes debugging then remember crap... Lol.... – Namphibian Aug 26 '14 at 03:35
  • I have version 3.5 and i already set lazy="true" in my dataTable. But still load() method in lazyDataModel is not getting called. Do you have any idea ? – Sahan Maldeniya May 14 '15 at 05:56
  • Even with Datatable attribute lazy="true", some other Datatable attributes can inhibit lazy loading, causing UnsupportedOperationException with message "Lazy is loading not implemented", (generated by the load() stub in LazyDataModel). Try removing attributes such as sortMode and sortBy, and set paginator="true" rather than having it set by a bean property. – J Slick Jul 27 '16 at 03:03
0
  1. If you are IE, be sure to check which so-called "compatibility mode" it is quirking in. I have had very annoying problems with lazy datatable failing to call its load method after I typed text into the filter field. After much wasted time, I eventually realized that the browser was running in default mode 7. Datatable lazy load works for modes 8, 9, 10
  2. If your lazy datatable is in a dialog, then be sure to place the dialog within the form, otherwise, typing values into a filter field will not submit to the load method.
J Slick
  • 929
  • 11
  • 17