我有一个空白的表面lazydatamodel表。调用lazydatamodel的load方法并正确执行查询。如果我对来自load方法的返回数据设置了制动点,则它包含预期的数据。但是在xhtml中仍然有一个空表。
lazydatamodel类:
@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;
}
.....
调用lazydatamodel的bean:
@Named
@ViewScoped
public class ModeratorDashboardBean implements Serializable {
private static final long serialVersionUID = -8586184444671684610L;
@Inject
private LazyEventDataModel lazyEventDatamodel;
public LazyEventDataModel getLazyEventDatamodel() {
return lazyEventDatamodel;
}
}
xhtml数据表文件:
<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>
答案 0 :(得分:1)
我也猜测
this.setRowCount(count(filters));
错了。假设是正确的:
this.setRowCount(data.size());
答案 1 :(得分:0)
如果您删除了h:outputText(本来会想到的),它将起作用
<p:column headerText="Event" filterBy="#{event.name}" filterMatchMode="contains" sortBy="event.name">
#{event.name}"
</p:column>