2010-08-12 75 views
4

當我爲已存在的REST服務創建一個簡單的客戶端時,我注意到smartGWT的RestDataSource類在它可以理解的xml類型中受到限制。所有的REST資源必須在以下格式的XML響應..使用SmartGWT消費REST服務

<response> 
    <status>0</status> 
    <startRow>0</startRow> 
    <endRow>10</endRow> 
    <totalRows>50</totalRows> 
    <data> 
     <record> 
      <someField>value</someField> 
      <someOtherField>value</someOtherField> 
     </record> 
     <record> 
      <someField>value</someField> 
      <someOtherField>value</someOtherField> 
     </record> 
     ... 
    </data> 
</response> 

..其中僅變種是someField/someOtherField標籤。

這個結構,比名稱/值對多一點,不會爲我們工作。

然後我看到了SmartGWT的展示這個演示...

http://www.smartclient.com/smartgwtee/showcase/#data_integration_server_rss

它展示瞭如何在像這樣顯示任意格式使用XML ...

package com.smartgwt.sample.showcase.client.webservice; 

import com.smartgwt.client.data.DataSource; 
import com.smartgwt.client.data.fields.DataSourceTextField; 
import com.smartgwt.client.data.fields.DataSourceLinkField; 
import com.smartgwt.client.widgets.Canvas; 
import com.smartgwt.client.widgets.grid.ListGrid; 
import com.smartgwt.sample.showcase.client.PanelFactory; 
import com.smartgwt.sample.showcase.client.ShowcasePanel; 

public class RssSample implements EntryPoint { 

    public void onModuleLoad() { 
     DataSource dataSource = new DataSource(); 
     dataSource.setDataURL("http://rss.slashdot.org/Slashdot/slashdot"); 
     dataSource.setRecordXPath("//default:item"); 

     DataSourceTextField titleField = new DataSourceTextField("title", "Title"); 
     DataSourceLinkField linkField = new DataSourceLinkField("link", "Link"); 

     dataSource.setFields(titleField, linkField); 

     ListGrid grid = new ListGrid(); 
     grid.setAutoFetchData(true); 
     grid.setHeight(200); 
     grid.setWidth100(); 
     grid.setDataSource(dataSource); 

     grid.draw(); 
    } 

} 

這適用於GETs,但PUT,POST和DELETE如何?

任何人都可以共享一些代碼或指向一個資源,演示如何從SmartGWT客戶端執行其他RESTful操作?

感謝

回答