[ECSide] ECSide分页显示出现问题

no87木 2012-02-28

我在使用ecside数据库分页出现实际显示的内容和工具栏提示的不相符

我的servlet如下

List<Note> all = null;

              int currentPage = 1;

              int lineSize = 2;

              int allRecorders = 0;

              NoteDAO noteDAO = DAOFactory.getNoteDAOInstance();

              Limit limit = RequestUtils.getLimit(request);

              Sort sort = limit.getSort();

              Map sortValueMap = sort.getSortValueMap();

              FilterSet filterSet = limit.getFilterSet();

              Map filterPropertyMap = filterSet.getPropertyValueMap();

              try {

                  allRecorders = noteDAO.getAllCount(sortValueMap,

                         filterPropertyMap);

                  int[] rowStartEnd = RequestUtils.getRowStartEnd(request,

                         allRecorders, lineSize);

                  // limit.setRowAttributes(allRecorders, lineSize);

                  //

                  // int offset = 0;

                  // int[] rowStartEnd = new int[] {

                  // limit.getRowStart() + offset,

                  // limit.getRowEnd() + offset };

                  // if (lineSize > allRecorders) {

                  // currentPage = 1;

                  // } else {

                  // currentPage = RequestUtils.getPageNo(request);

                  // }

                  // System.out.println("------>"+RequestUtils.getTotalRowsFromRequest(request));

                  // int showSize = limit.getCurrentRowsDisplayed();

                  all = noteDAO.findAll(rowStartEnd[0], rowStartEnd[1],

                         sortValueMap, filterPropertyMap);

              } catch (Exception e) {

                  e.printStackTrace();

              }

              request.setAttribute("all", all);

 

dao

public List<Note> findAll(int startRow, int endRow, Map sortValueMap,

           Map filterPropertyMap) throws Exception {

       List<Note> all = new ArrayList<Note>();

       int size = endRow - startRow;

       StringBuffer sql = new StringBuffer();

       sql.append("select * from ");

       StringBuffer sqlWhere = new StringBuffer(" where 1=1 ");

       if (filterPropertyMap != null && !filterPropertyMap.isEmpty()) {

           String filterProperty;

           String filterValue;

           filterProperty = "title";

           filterValue = (String) filterPropertyMap.get(filterProperty);

           if (filterValue != null) {

              sqlWhere.append(" and ").append(filterProperty).append(" = ")

                     .append(StringEscapeUtils.escapeSql(filterValue))

                     .append("'");

           }

           filterProperty = "author";

           filterValue = (String) filterPropertyMap.get(filterProperty);

           if (filterValue != null) {

              sqlWhere.append(" and ").append(filterProperty).append(

                     " like' ").append(

                     StringEscapeUtils.escapeSql(filterValue)).append("'");

           }

           filterProperty = "content";

           filterValue = (String) filterPropertyMap.get(filterProperty);

           if (filterValue != null) {

              sqlWhere.append(" and ").append(filterProperty).append(" = ")

                     .append(StringEscapeUtils.escapeSql(filterValue))

                     .append("'");

           }

       }

       if (sortValueMap != null && !sortValueMap.isEmpty()) {

           sql.append(" (select * from note ");

           sql.append(sqlWhere);

           sql.append(ECSideUtils.getDefaultSortSQL(sortValueMap));

           sql.append(" )as a");

       } else {

           sql.append(" note ");

           sql.append(sqlWhere);

       }

       sql.append("limit ? offset ?");

       PreparedStatement pstat = null;

       System.out.println("allSQL:"+sql.toString()+":size"+size+":"+startRow);

       try{

           pstat = dbc.getConnection().prepareStatement(sql.toString());

           pstat.setInt(1, size);

           pstat.setInt(2, startRow);

           ResultSet rs = pstat.executeQuery();

           Note note = null;

           while(rs.next()){

              note = new Note();

              note.setId(rs.getInt(1));

               note.setTitle(rs.getString(2));

              note.setAuthor(rs.getString(3));

              note.setContent(rs.getString(4));

              all.add(note);

           }

           rs.close();

           pstat.close();

       }catch (Exception e) {

           throw e;

       }finally{

           dbc.close();

       }

       System.out.println("all.size():"+all.size());

       return all;

    }

jsp页面:

<ec:table
    items="all"
    var="record"
    retrieveRowsCallback="limit"
    sortRowsCallback="limit"
    filterRowsCallback="limit"
    action="NoteServlet?status=selectall"
    useAjax="true"
    pageSizeList="2,5,10,50"
    title="NOTE信息"
    editable="true"
    xlsFileName="NOTE1.xls"
    csvFileName="NOTE2.csv"
    pdfFileName="NOTE3.pdf"
    showPrint="true"
    sortable="true"
    filterable="true"
    resizeColWidth="true"
    classic="true"
    updateAction="NoteServlet?status=update"
    insertAction="NoteServlet?status=insert"
    deleteAction="NoteServlet?status=delete">
    <ec:row recordKey="${record.id}">
     <ec:column width="50" property="id" title="序号" editable="false" ></ec:column>
     <ec:column width="200" property="title" title="标题"></ec:column>
     <ec:column width="100" property="author" title="作者"></ec:column>
     <ec:column width="200" property="content" title="内容"></ec:column>
    </ec:row>
   </ec:table>

 

Global site tag (gtag.js) - Google Analytics