Problem using dataTable with ExtendedDataModel on an SEAM up
zhyuhong Jul 17, 2009 5:21 PMI am using SEAM 2.1.2 on Jboss 5.1.0GA, I cannot get dataTable to work. The problem is that none of my data show up. I used a debugger to trace on what is going on. It seems that
- The "getRowCount()" returns the correct number;
- The the "walk()" method is never called. Neither any of the methods related to the "key".
- What is repeatedly called was "isRowAvailable()" and "setRowIndex()"
As I understand the "walk()" is supposed to do the work. I am obviously missing something really obvious so that that is not called; just I cannot see it. How does the table on the page and data model to communicate which column is the key?
I used the richFaces HinernateDataModel example and simplified it to just what is left in the following for testing,
import java.io.IOException; import java.util.List; import javax.faces.context.FacesContext; import org.ajax4jsf.model.DataVisitor; import org.ajax4jsf.model.ExtendedDataModel; import org.ajax4jsf.model.Range; import org.ajax4jsf.model.SequenceRange; import org.jboss.seam.Component; import org.richfaces.model.FilterField; import org.richfaces.model.Modifiable; import org.richfaces.model.SortField2; import com.way.wcc.model.User; import com.way.wcc.model.UserSearch; import com.way.wcc.user.dao.UserDao; public class TestDataModel extends ExtendedDataModel implements Modifiable { private Integer rowKey; private User dataItem; private SequenceRange cachedRange; private List<User> cachedItems; private static boolean areEqualRanges(SequenceRange range1, SequenceRange range2) { if (range1 == null || range2 == null) { return range1 == null && range2 == null; } else { return range1.getFirstRow() == range2.getFirstRow() && range1.getRows() == range2.getRows(); } } @Override public Object getRowKey() { return rowKey; } @Override public void setRowKey(Object key) { this.rowKey = (Integer) key; this.dataItem = null; if (this.rowKey != null) { UserDao userDao = (UserDao)Component.getInstance("userDao"); this.dataItem = (User) userDao.getUser(rowKey); } } @Override public void walk(FacesContext facesContext, DataVisitor visitor, Range range, Object argument) throws IOException { SequenceRange sequenceRange = (SequenceRange) range; int first = 0; int rows = 5; if (this.cachedItems == null || !areEqualRanges(this.cachedRange, sequenceRange)) { if (sequenceRange != null) { first = sequenceRange.getFirstRow(); rows = sequenceRange.getRows(); } this.cachedRange = sequenceRange; UserDao userDao = (UserDao)Component.getInstance("userDao"); this.cachedItems = userDao.findUsers(new UserSearch(), first, rows); } for (User item: cachedItems) { visitor.process(facesContext, item.getId(), argument); } } @Override public int getRowCount() { UserDao userDao = (UserDao)Component.getInstance("userDao"); return userDao.findUserCount(new UserSearch()); } @Override public Object getRowData() { return this.dataItem; } @Override public int getRowIndex() { return -1; } @Override public Object getWrappedData() { return null; } @Override public boolean isRowAvailable() { return (this.dataItem != null); } @Override public void setRowIndex(int rowIndex) { } @Override public void setWrappedData(Object data) { } public void modify(List<FilterField> filterFields, List<SortField2> sortFields) { this.cachedItems = null; this.cachedRange = null; } }
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <style> .rich-filter-input{ width:50px; } </style> <h:form> <a4j:queue requestDelay="100" /> <rich:messages /> <rich:dataTable value="#{userListController.userList}" var="row" rows="10" reRender="datascroller" width="650"> <h:column> <h:outputText value="#{row.firstName}" /> </h:column> <f:facet name="footer"> <rich:datascroller id="datascroller" /> </f:facet> </rich:dataTable> </h:form> </ui:composition>