在添加惰性属性之前,我能够看到数据表中的数据。添加惰性属性后,数据表为空,因为我的调试点从未到达 LazyDataModel 的加载方法中。换句话说,加载方法没有被调用,我在我的 search() 中看到了 this.searchResults 之前的控件
我只是从 Web 服务(工作得很好)中得到我的结果,我已经查看了这里和这里的大部分链接。我确保设置了惰性属性和 setRowCount。可能有人可以帮助我找出问题所在。我正在使用 PrimeFaces 6.0、CDI、JSF 2.2、Deltaspike 1.7.2
这是我的 JSF
// other input form fields
<p:panel style="border-style : none;" styleClass="panelClass">
<h:panelGrid columns="2">
<!-- <h:commandButton action="#{search.search}" value="Search" styleClass="button_small_white" /> -->
<p:commandButton action="#{search.search}" ajax="true" update=":mainform:searchResultTable" value="Search" styleClass="button_small_white" />
<h:commandButton action="#{search.clear}" value="Clear" styleClass="button_small_white" />
</h:panelGrid>
</p:panel>
<br /><p:dataTable value="#{search.searchResults}" var="rec"
rowKey="rec.numTxt"
paginator="true" rows="10"
paginatorTemplate=" Display {RowsPerPageDropdown} Records {FirstPageLink}
{PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} "
rowsPerPageTemplate="10,25,50,100"
paginatorPosition="top"
rendered="#{not empty search.searchResults}"
id="searchResultTable"
widgetVar="searchTable"
lazy="true"
summary="RE Search Results are shown below">
<p:ajax event="page" listener="#{search.search}" update=":mainform:searchResultTable" />
<p:column headerText="">
<p:selectBooleanCheckbox value="#{rec.select}" />
</p:column>
...
</p:dataTable>
控制器
@Named("search")
@Stateful
@GroupedConversationScoped
@ConversationGroup(SearchGrp.class)
public class ReSearchController extends BaseWebServicesSearchController<ReSearchSummary>
implements ReGrp, ReSearchControllerLocal {
@Inject
private GroupedConversation conversation;
@Inject
private WindowContext windowContext;
private LazyDataModel<ReSearchSummary> searchResults;
...
@PostConstruct
@Override
public void init() {
// code for initializing my web services
search();
}
@Override
public String search(){
this.searchResults = new LazyDataModel<ReSearchSummary>() {
private static final long serialVersionUID = 4168363870903585956L;
@Override
public List<ReSearchSummary> load(int first, int pageSize, String sortField, SortOrder sortOrder,
Map<String, Object> filters) {
List<ReSearchSummary> resultsList = null;
resultsList = search(first, pageSize);
// rowCount
setRowCount(getResultCount());
// I do not need sorting oor filters os did not use them
return resultsList;
}
};
searchResults.setRowCount(getResultCount());
return "/cr-re-search.xhtml?faces-redirect=true";
}
@Override
public ArrayList<ReSearchSummary> search(int first, int pageSize){
// this is my webservice call, this works fine if I call it indepedently
// criteria gets the form inputs
return doSearch(criteria.getForm(), pageSize, first);
}
...
}
更新:将搜索按钮的 h:commandButton 转换为 p:commandButton
<p:commandButton action="#{search.search}" ajax="true" update=":mainform:searchResultTable" value="Search" styleClass="button_small_white" />
并在 p:dataTable 中添加了 p:ajax
<p:ajax event="page" listener="#{search.search}" update=":mainform:searchResultTable" />