代码之家  ›  专栏  ›  技术社区  ›  ivo

SmartGWT分页如何工作?

  •  2
  • ivo  · 技术社区  · 14 年前

    有人能给我解释一下在SmartGWT中分页是如何工作的吗?

    我看到它在 showcase 但是我在任何地方都找不到记录。(javadocs中的信息远远不足以理解正在发生的事情。)

    我有一个listgrid,以及一个与服务器交互的自定义数据源。

    假设我想在listgrid中设置25条记录的页面大小。

    我该怎么做:

    • 在列表网格中?
    • 在我的自定义数据源中(有权访问dsrequest和dsresponse对象)?
    • 在我的服务器上?

    smartgwt客户机发送给服务器的参数是什么,smartgwt客户机期望返回的参数是什么?

    1 回复  |  直到 14 年前
        1
  •  4
  •   Sanjiv Jivan    14 年前

    如果您使用的是智能GWT LGPL:

    请阅读restdatasource的javadocs,因为它详细解释了这一点: http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/data/RestDataSource.html

    还可以查看restdatasource示例: http://www.smartclient.com/smartgwt/showcase/#featured_restfulds

    如果你使用的是智能GWTEE,那么 1)如果您使用的是SQL连接器,那么您可以在服务器上编写0代码,因为智能GWT服务器端代码负责将数据绑定连接到数据库表。 2)如果需要对服务器数据绑定进行模式控制,可以在滚动(提取)或发生插入/更新/删除时调用自己的服务器API。请查看此示例的来源: http://www.smartclient.com/smartgwtee/showcase/#javabeans

    单击“查看源代码”按钮,检查supplyItemDMI类的源代码。请注意如何获取请求的起始行和结束行参数。

    // By default, for a DSRequest of type "fetch", a method named "fetch" is invoked.  
    // You can customize this via the <serverObject> declaration.  
    public DSResponse fetch(DSRequest dsRequest)  
        throws Exception {  
       log.info("procesing DMI fetch operation");  
    
        // Fetch a List of matching SupplyItem Beans from some pre-existing Java object model  
        // provided by you, represented by "SupplyItemStore" in this example  
        List matchingItems =  
            SupplyItemStore.findMatchingItems((Long) dsRequest.getFieldValue("itemID"),  
                    (String) dsRequest.getFieldValue("itemName"));  
    
        // this implementation shows data paging (returning only ranges of requested records)  
        long startRow = dsRequest.getStartRow();  
        long endRow = dsRequest.getEndRow();  
    
        long totalRows = matchingItems.size();  
        DSResponse dsResponse = new DSResponse();  
        dsResponse.setTotalRows(totalRows);  
        dsResponse.setStartRow(startRow);  
    
        endRow = Math.min(endRow, totalRows);  
        dsResponse.setEndRow(endRow);  
    
        // trim the data to the requested range of records.  In a real application, the startRow  
        // and endRow would be passed to the ORM layer or to SQL for maximum efficiency.  
        List results;  
        if (totalRows > 0) {  
            results = matchingItems.subList((int) dsResponse.getStartRow(),  
                    (int) dsResponse.getEndRow());  
        } else {  
            results = matchingItems;  
        }  
    
        // just return the List of matching beans  
        dsResponse.setData(results);  
    
        return dsResponse;  
    }