-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm trying to implement Read on demand data to grid. Data size is known at page construction time. About first 60 lines are rendered at page start, and they are rendered correctly. Then user slowly scrolls down then rows are rendered. If user scrolls to bottom quickly and then back then content of the grid is usually somehow terribly crippled (seems that all data degraded to a single not readable column)and the rows does not ask rendering any other remaining row.
.zul
<zk xmlns:n="native">
<zscript>
cz.profinit.dagensia.tradeportal.gui.common.NavbarViewModel.selectMenuItem("navi-secured-account-log");
</zscript>
<span self="@define(pagetitle)">Finance log</span>
<div self="@define(content)">
<n:h1>${labels.financeLog.title}</n:h1>
<idspace apply="foo.AccountFinanceLogController">
<grid id="grid" vflex="true">
</grid>
</idspace>
</div>
</zk>
java public class AccountFinanceLogController extends GenericAutowireComposer {
private static final long serialVersionUID = -2835351800280322569L;
private LoggedInUserService loggedInUserService;
private UserActionAuditServiceApi userActionAuditService;
private Grid grid;
private UserTo loggedUser;
private List<LogItemTo> userLogItems = new ArrayList<>();
private static long PAGE_SIZE = 20;
private int currentPageNumber = 0;
private Date dateFrom;
public void doAfterCompose(Component window) throws Exception {
super.doAfterCompose(window);
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
dateFrom = calendar.getTime();
loggedInUserService = (LoggedInUserService) SpringUtil.getBean("loggedInUserService");
userActionAuditService = (UserActionAuditServiceApi) SpringUtil.getBean("userActionAuditServiceProxy");
loggedUser = loggedInUserService.getLoggedInUser();
updateLogItemList();
//create and setup grid
grid.setRowRenderer(new LogGridRowRender());
grid.setEmptyMessage(Labels.getLabel("financeLog.noLogData"));
grid.setSclass("table table-hover");
grid.setZclass(null);
generateColumns();
grid.setModel(new LogGridDataModel(userActionAuditService.getLogItemCountForUser(loggedUser.getId(), dateFrom)));
grid.setHeight("400px");
}
private void updateLogItemList() {
userLogItems.addAll(userActionAuditService.getLogItemsForUser(this.loggedUser.getId(), dateFrom, currentPageNumber * PAGE_SIZE, PAGE_SIZE));
}
private void generateColumns() {
String[] colHeaders = new String[5];
colHeaders[0] = Labels.getLabel("financeLog.id");
colHeaders[1] = Labels.getLabel("financeLog.date");
colHeaders[2] = Labels.getLabel("financeLog.address");
colHeaders[3] = Labels.getLabel("financeLog.type");
colHeaders[4] = Labels.getLabel("financeLog.description");
Columns columns = new Columns();
columns.setParent(grid);
columns.setSizable(true);
for (String colHeader : colHeaders) {
Column col = new Column();
columns.appendChild(col);
col.setLabel(colHeader);
col.setAlign("center");
}
}
public class LogGridRowRender implements RowRenderer {
@Override
public void render(Row row, Object data, int index) throws Exception {
if (data != null && data instanceof List) {
for (String object : (List<String>) data) {
Label label = new Label();
if (object != null) {
label.setValue(object);
}
label.setParent(row);
}
}
}
}
public class LogGridDataModel extends AbstractListModel implements ListSubModel, java.io.Serializable {
private static final long serialVersionUID = -739704260447180304L;
private long size;
public LogGridDataModel(long size) {
this.size = size;
}
public Object getElementAt(int index) {
if (index < size && index >= 0) {
if (!(size == userLogItems.size()) && index >= userLogItems.size() - PAGE_SIZE) { //Load another data
while (!(size == userLogItems.size()) && index >= userLogItems.size() - PAGE_SIZE) { //User may scroll fast and some rows (indexes) may be skipped
currentPageNumber++;
updateLogItemList();
}
grid.getRows().invalidate();
}
List<String> rowData = new ArrayList<>();
LogItemTo item = userLogItems.get(index);
rowData.add(item.getId().toString());
rowData.add(item.getCreatedTimestamp().toString());
rowData.add(item.getIp());
rowData.add(item.getLogAction().name());
rowData.add(item.getDetail());
return rowData;
}
return null;
}
@Override
public int getSize() {
return (int) size;
}
@Override
public ListModel getSubModel(Object value, int rows) {
return null;
}
}
}
I would expect that line grid.getRows().invalidate(); won't be needed at all But without it behaviour is even worse.
Since the the problem is not very repeatable I do not have idea, what is the problem. Is the problem in my code or in Zkoss. I'm using 7.0.1, tried also 7.0.2 but with the same result
Asked: 2014-07-07 16:31:42 +0800
Seen: 54 times
Last updated: Jul 07 '14