13 Replies Latest reply on Jul 15, 2010 3:46 PM by Yuhong Zhang

    Problem using dataTable with ExtendedDataModel on an SEAM up

    Yuhong Zhang Newbie

      I 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();
       public Object getRowKey() {
       return rowKey;
       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);
       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);
       public int getRowCount() {
       UserDao userDao = (UserDao)Component.getInstance("userDao");
       return userDao.findUserCount(new UserSearch());
       public Object getRowData() {
       return this.dataItem;
       public int getRowIndex() {
       return -1;
       public Object getWrappedData() {
       return null;
       public boolean isRowAvailable() {
       return (this.dataItem != null);
       public void setRowIndex(int rowIndex) {
       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"
       <a4j:queue requestDelay="100" />
       <rich:messages />
       <rich:dataTable value="#{userListController.userList}" var="row" rows="10"
       reRender="datascroller" width="650">
       <h:outputText value="#{row.firstName}" />
       <f:facet name="footer">
       <rich:datascroller id="datascroller" />