2010-05-20 48 views
2

有人可以向我解释在SmartGWT中寻呼是如何工作的吗?SmartGWT分页如何工作?

我看到它在showcase中工作,但我无法在任何地方找到它。 (javadoc中的信息远远不足以理解正在发生的事情。)

我有一个ListGrid和一个与我的服务器交互的自定义​​DataSource。

比方说,我想在ListGrid中设置25个记录的页面大小。

我有什么做的事:

  • 在ListGrid?
  • 在我的自定义数据源(有权访问DSRequest和DSResponse对象)?
  • 在我的服务器?

SmartGWT客户端发送给服务器的参数是什么,SmartGWT客户端期望的参数是什么?

回答

4

如果你使用智能GWT LGPL:

请阅读RestDataSource的Javadoc中,因为它解释对此进行了详细:http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/data/RestDataSource.html

也可以看看在RestDataSource样本:http://www.smartclient.com/smartgwt/showcase/#featured_restfulds

如果你正在使用Smart GWT EE,然后 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; 
}