Jsf 使用LazyDataModel分页时,选定的rowkey为空
我使用的是PrimeFaces5.0。我已经实现了LazyDataModel,并且能够加载行,但是,当我分页时,会调用getRowDataString rowKey,但rowKey为null。它在第一页上获得正确的键,但在我分页到下一页或上一页时总是空的Jsf 使用LazyDataModel分页时,选定的rowkey为空,jsf,primefaces,pagination,Jsf,Primefaces,Pagination,我使用的是PrimeFaces5.0。我已经实现了LazyDataModel,并且能够加载行,但是,当我分页时,会调用getRowDataString rowKey,但rowKey为null。它在第一页上获得正确的键,但在我分页到下一页或上一页时总是空的 <p:dataTable id="sublTableId" value="#{submissionListBean.lazyModel}" var="selRow"
<p:dataTable id="sublTableId"
value="#{submissionListBean.lazyModel}"
var="selRow"
selectionMode="single"
selection="#{submissionListBean.selectedSubmissionListRec}"
resizableColumns="true"
paginator="true"
rows="50"
paginatorPosition="both"
paginatorAlwaysVisible="true"
scrollable="true"
scrollHeight="300px;"
scrollWidth="100px;"
frozenColumns="5"
paginatorTemplate="{PreviousPageLink} {NextPageLink}"
lazy="true"
rowIndexVar="rowIndex">
<p:ajax event="rowSelect"
update=":submissionListForm:thrdListBtn"
listener="#{submissionListBean.onRowSelect}"/>
LazySubmissionListDataModel.java
public class LazySubmissionListDataModel extends LazyDataModel<AuditSubmissionListDto> {
private static final long serialVersionUID = 429415464812534969L;
private List<AuditSubmissionListDto> datasource;
private AuditSubmissionListDto request;
private IAuditService auditService;
private CmUserContext userContext;
int startPage = 1;
int totalRowCount;
public LazySubmissionListDataModel(CmUserContext userContext, IAuditService auditService,
AuditSubmissionListDto request) {
this.auditService = auditService;
this.userContext = userContext;
this.request = request;
}
@Override
public List<AuditSubmissionListDto> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
datasource = new ArrayList<AuditSubmissionListDto>();
// Calculate pages for pagination
if (first == 0) {
startPage = 1;
} else {
startPage = (first / pageSize) + 1;
}
// Call the service to get the resultlist
try {
datasource = getAuditService().getSubmissionListRecords(userContext, request, pageSize, startPage);
if ((datasource != null) && (datasource.size() > 0)) {
totalRowCount = datasource.get(0).getTotalRowsCount().intValue();
}
setRowCount(totalRowCount);
setWrappedData(datasource);
} catch (BesCmUiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return datasource;
}
@Override
public AuditSubmissionListDto getRowData(String rowKey) {
for (AuditSubmissionListDto dto : datasource) {
if (dto.getSubmissionId().equals(rowKey)) {
return dto;
}
}
return null;
}
@Override
public AuditSubmissionListDto getRowData() {
// TODO Auto-generated method stub
return super.getRowData();
}
@Override
public String getRowKey(AuditSubmissionListDto dto) {
return dto.getSubmissionId();
}
/*
* (non-Javadoc)
* @see org.primefaces.model.LazyDataModel#isRowAvailable()
*/
@Override
public boolean isRowAvailable() {
// TODO Auto-generated method stub
return super.isRowAvailable();
}
/*
* (non-Javadoc)
* @see org.primefaces.model.LazyDataModel#getRowCount()
*/
@Override
public int getRowCount() {
// TODO Auto-generated method stub
return super.getRowCount();
}
/*
* (non-Javadoc)
* @see org.primefaces.model.LazyDataModel#getRowIndex()
*/
@Override
public int getRowIndex() {
// TODO Auto-generated method stub
return super.getRowIndex();
}
/*
* (non-Javadoc)
* @see org.primefaces.model.LazyDataModel#setRowIndex(int)
*/
@Override
public void setRowIndex(int rowIndex) {
// TODO Auto-generated method stub
super.setRowIndex(rowIndex);
}
/*
* (non-Javadoc)
* @see org.primefaces.model.LazyDataModel#setWrappedData(java.lang.Object)
*/
@Override
public void setWrappedData(Object list) {
// TODO Auto-generated method stub
super.setWrappedData(list);
}
/*
* (non-Javadoc)
* @see org.primefaces.model.LazyDataModel#getPageSize()
*/
@Override
public int getPageSize() {
// TODO Auto-generated method stub
return super.getPageSize();
}
/*
* (non-Javadoc)
* @see org.primefaces.model.LazyDataModel#getWrappedData()
*/
@Override
public Object getWrappedData() {
// TODO Auto-generated method stub
return super.getWrappedData();
}
/*
* (non-Javadoc)
* @see org.primefaces.model.LazyDataModel#setPageSize(int)
*/
@Override
public void setPageSize(int pageSize) {
// TODO Auto-generated method stub
super.setPageSize(pageSize);
}
}
最后,我终于找到了问题所在。xhtml中的frozenColumn属性将rowkey设置为。我也能够用Primefaces showcase中给出的标准汽车的例子来复制它。如果有人知道这是否有一个解决方案,如果你能友好地张贴感谢。 谢谢 .xhtml
<p:dataTable var="car" value="#{tableBean.lazyModel}" paginator="true" rows="10" lazy="true"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink}
{CurrentPageReport}{NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15"
selection="#{tableBean.selectedCar}" selectionMode="single"
scrollable="true" frozenColumns="1">
<p:ajax event="rowSelect" listener="#{tableBean.onRowSelect}" />
您已经覆盖了bean中的所有方法,而没有绝对的需要,这会使您的代码变得不必要的混乱。除非绝对有必要重写这些方法,否则就把它们去掉。在本例中,您只需执行rowKey={selRow.submissionId}-的一个属性。无需显式重写关联bean中的getRowKey方法。链接的帖子也相当混乱。将s与a结合使用的意图完全未明。使用a的积垢操作可以以相当整洁的方式执行/处理。您好,非常感谢您的回复。我添加了rowKey={selRow.submissionId},并从LazySubmissionListDataModel.java中删除了所有被重写的方法,只保留了getter和setter,但所选行在RowSelect上仍然为null。托管Bean:public void onRowSelectSelectEvent事件{String actionName=ON_row_SELECT;log.debugSubmissionListBean:+actionName;try{AuditSubmissionListDToSelectedObj=AuditSubmissionListDtoevent.getObject;我在您的支持bean中找不到该侦听器方法。您是否有类似于public void onRowSelectSelectEvent事件{…}在您的支持bean中?请在PF中提交一个问题issuelist@Kukeltje,是的,我已在PF问题列表中提交和发布:问题7850:
<p:dataTable var="car" value="#{tableBean.lazyModel}" paginator="true" rows="10" lazy="true"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink}
{CurrentPageReport}{NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15"
selection="#{tableBean.selectedCar}" selectionMode="single"
scrollable="true" frozenColumns="1">
<p:ajax event="rowSelect" listener="#{tableBean.onRowSelect}" />