With reference to the suggestion given in the post here i tried implementing lazy loading with live scrolling to handle large data sets,but live scrolling doesn't happen when both rows and scrollRows attributes of datatable are used.If i remove rows attribute then no records would be displayed.Here is my code snippet that i tried.Can someone please help me out if i am doing anything wrong.
JSF code snippet
<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>
Managed 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 class
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 class
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;
}
}
}
as I understand the documentation using rows would conflict with scrollRows.
Here's the PrimeFaces documentation about these two attributes:
Now the problem here is not only the rows, I think it's
scrollWidth="84%" scrollHeight="81%"
As the documentation, these two attributes are Integer(s), so you won't see any records infact because the scrollHeight is defined wrong.
Try to set them into fixed integer pixels, like 500.
Hope this helps.