simonC
simonC

Reputation: 4337

primefaces lazydatamodel table is empty

I have a primefaces lazydatamodel table which is empty. The load method of the lazydatamodel is called and the query is executed correctly. If I put a brakepoint on the returning data from load method it contains the expected data. But in the xhtml there is still an empty table.

The lazydatamodel class:

@Named
@Stateless
public class LazyEventDataModel extends LazyDataModel<Event> implements Serializable {

private static final long serialVersionUID = -1044044395695736241L;

@Inject @YpayDB EntityManager em;

@Override
public  List<Event> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {

    if(sortField == null || sortField.equals("")){
        sortField = "event.startUTC";
    }

    List<Event> data = selectData(first, pageSize, sortField, DataUtilsWeb.transformSortOrder(sortOrder), filters);
    //row count
    this.setRowCount(count(filters));

    return data;
}
.....

The bean that is calling the lazydatamodel:

@Named
@ViewScoped
public class ModeratorDashboardBean implements Serializable {

private static final long serialVersionUID = -8586184444671684610L;

@Inject
private LazyEventDataModel lazyEventDatamodel;

public LazyEventDataModel getLazyEventDatamodel() {
    return lazyEventDatamodel;
}

}

The xhtml datatable file:

<p:dataTable emptyMessage="No data" id="dataTable" var="event" value="#{moderatorDashboardBean.lazyEventDatamodel}"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                     paginator="true"  paginatorPosition="bottom" rowsPerPageTemplate="10,20,30" rows="20" rowKey="#{event.idEvent}"   
                     lazy="true" style="width:100%"  sortBy="event.startUTC" sortOrder="DESCENDING" filterDelay="400">

                    <p:column headerText="Date from" >
                         <h:outputText value="#{event.start}" >
                                <f:convertDateTime pattern="dd.MM.yy HH:mm" />  
                            </h:outputText>
                    </p:column>
                    <p:column headerText="Date to" >
                         <h:outputText value="#{event.end}" >
                                <f:convertDateTime pattern="dd.MM.yy HH:mm" />  
                            </h:outputText>
                    </p:column>
                     <p:column headerText="Event" filterBy="#{event.name}" filterMatchMode="contains" sortBy="event.name">
                         <h:outputText value="#{event.name}" >
                            </h:outputText>
                    </p:column>


                </p:dataTable>

Upvotes: 0

Views: 2622

Answers (2)

Dmitry Zorin
Dmitry Zorin

Reputation: 13

It will work if you take away h:outputText(who would have thought)

<p:column headerText="Event" filterBy="#{event.name}" filterMatchMode="contains" sortBy="event.name">
    #{event.name}"
</p:column>

Upvotes: 0

Andreas
Andreas

Reputation: 553

I also guess

this.setRowCount(count(filters));

is wrong. Assume to be correct:

this.setRowCount(data.size());

Upvotes: 1

Related Questions