参照在后给出的建议, 在这里我想实现延迟加载与现场滚动处理大型数据集,但现场的滚动不发生时两列和数据表scrollRows属性used.If我删除然后行属性没有记录将displayed.Here是我的代码片段,我tried.Can有人请帮助我,如果我做错了什么。
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;
}
}
}