参考帖子here中给出的建议我尝试使用实时滚动实现延迟加载来处理大型数据集,但当行和<时,不会发生实时滚动使用了数据表的strong> scrollRows 属性。如果我删除了行属性,那么就不会显示任何记录。这是我试过的代码片段。如果有的话请有人帮帮我做错了。
JSF代码段
<p:dataTable id="arcRecList" var="data"
value="#{archivedRecordBean.archModel}" lazy="true"
tableStyle="table-layout:auto; width:80%;" styleClass="datatable"
scrollable="true" scrollWidth="84%" scrollHeight="81%"
columnClasses="columnwidth" liveScroll="true" scrollRows="20"
filteredValue="#{archivedRecordBean.filteredArchiveItems}"
resizableColumns="true" rows="20">
<p:column headerText="Insured" filterBy="#{data.insuredName}"
sortBy="#{data.insuredName}" filterMatchMode="contains"
style="width:15%;white-space:pre-line;" escape="false"
filterStyle="width:80% !important; margin-top:25px;"
sortFunction="#{archivedRecordBean.sortColumn}">
<h:outputText value="#{data.insuredName}" />
<!-- style="width:250px" -->
</p:column>
.
.
.
</p:dataTable>
托管bean
@ManagedBean
@ViewScoped
public class ArchivedRecordBean implements Serializable {
private List<LPINFO> archiveItems=null;
private List<LPINFO>filteredArchiveItems;
private LPINFO objLPINFO=null;
JdbcConnection jdbcConnection=null;
Connection connection=null;
Statement selectStmt=null;
ResultSet rs=null;
private transient LazyDataModel<LPINFO> archModel;
public ArchivedRecordBean()
{
getArchiveFields();
}
@PostConstruct
public void init()
{
archModel=new LazyArchiveDataModel(archiveItems);
}
public List<LPINFO> getArchiveItems() {
System.out.println("inside getter");
return archiveItems;
}
public void setArchiveItems(List<LPINFO> archiveItems) {
this.archiveItems = archiveItems;
}
public LPINFO getObjLPINFO() {
return objLPINFO;
}
public void setObjLPINFO(LPINFO objLPINFO) {
this.objLPINFO = objLPINFO;
}
public List<LPINFO> getFilteredArchiveItems() {
return filteredArchiveItems;
}
public void setFilteredArchiveItems(List<LPINFO> filteredArchiveItems) {
this.filteredArchiveItems = filteredArchiveItems;
}
public LazyDataModel<LPINFO> getArchModel() {
return archModel;
}
public void setArchModel(LazyDataModel<LPINFO> archModel) {
this.archModel = archModel;
}
public void getArchiveFields()
{
System.out.println("inside getArchiveFields");
ArchiveRecordsDao daoObject=new ArchiveRecordsDao();
archiveItems=daoObject.getArchiveRecords();
}
}
DAO课程
public class ArchiveRecordsDao {
JdbcConnection con = null;
Connection connection;
Statement selectStmt;
public ResultSet rs = null;
private List<LPINFO> archiveItems = null;
public LPINFO objWorkSpaceItem = null;
public List<LPINFO> getArchiveRecords()
{
try
{
con=new JdbcConnection();
connection=con.getJdbcConnection();
selectStmt=connection.createStatement();
String query="select * from LPINFO where LPINFO.ClearDate < (select TOP 1 Tbl_CurrentYear.CurrentYear from dbo.Tbl_CurrentYear)"
+"AND (LPINFO.ClearDate is not null)";
rs=selectStmt.executeQuery(query);
archiveItems=new ArrayList<LPINFO>();
while(rs.next())
{
objWorkSpaceItem=new LPINFO();
objWorkSpaceItem.setInsuredName(rs.getString("InsuredName"));
.
.
.
archiveItems.add(objWorkSpaceItem);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return archiveItems;
}
}
LazyDataModel类
public class LazyArchiveDataModel extends LazyDataModel<LPINFO> {
private List<LPINFO> datasource;
public LazyArchiveDataModel(List<LPINFO> datasource) {
this.datasource = datasource;
}
@Override
public void setRowIndex(int rowIndex) {
/*
* The following is in ancestor (LazyDataModel):
* this.rowIndex = rowIndex == -1 ? rowIndex : (rowIndex % pageSize);
*/
if (rowIndex == -1 || getPageSize() == 0) {
super.setRowIndex(-1);
}
else
super.setRowIndex(rowIndex % getPageSize());
}
@Override
public LPINFO getRowData(String rowKey) {
for(LPINFO lpinfo : datasource) {
if(lpinfo.getLPID().equals(rowKey))
return lpinfo;
}
return null;
}
@Override
public Object getRowKey(LPINFO lpinfo) {
return lpinfo.getLPID();
}
@Override
public List<LPINFO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
List<LPINFO> data = new ArrayList<LPINFO>();
//filter
for(LPINFO lpinfo : datasource) {
boolean match = true;
for(Iterator<String> it = filters.keySet().iterator(); it.hasNext();) {
try {
String filterProperty = it.next();
String filterValue = filters.get(filterProperty);
String fieldValue = String.valueOf(lpinfo.getClass().getField(filterProperty).get(lpinfo));
if(filterValue == null || fieldValue.startsWith(filterValue)) {
match = true;
}
else {
match = false;
break;
}
} catch(Exception e) {
match = false;
}
}
if(match) {
data.add(lpinfo);
}
}
//sort
/*if(sortField != null) {
Collections.sort(data, new LazySorter(sortField, sortOrder));
}*/
//rowCount
int dataSize = data.size();
this.setRowCount(dataSize);
//paginate
if(dataSize > pageSize) {
try {
return data.subList(first, first + pageSize);
}
catch(IndexOutOfBoundsException e) {
return data.subList(first, first + (dataSize % pageSize));
}
}
else {
return data;
}
}
}
答案 0 :(得分:0)
据我所知,使用行的文档会与scrollRows冲突。
以下是关于这两个属性的PrimeFaces文档:
行 :(整数)每个页面显示的行数。(分页)
scrollRows :(整数)实时滚动上要加载的行数。(滚动)
现在这里的问题不仅仅是行,我认为它是scrollWidth="84%" scrollHeight="81%"
作为文档,这两个属性是Integer(s),因此您不会看到任何记录,因为scrollHeight定义错误。
scrollHeight :(整数)滚动视口高度。
scrollWidth (整数)滚动视口宽度。
尝试将它们设置为固定的整数像素,例如500。
希望这有帮助。