在为REST服务创建一个简单的客户机时,我注意到,smartGWT的RestDataSource类仅限于它能够理解的xml类型。所有REST资源都必须以以下格式使用XML进行响应。
<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>。。其中,仅变体的是某个字段/某个其他字段标记。
这个结构,只不过是名称/值对,对我们不起作用。
然后我在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();
}
} 这对于GET来说很好,但是but、POST和DELETE又如何呢?
有人能分享一些代码或向我指出一个资源,该资源演示如何从RESTful客户端执行其他SmartGWT操作吗?
谢谢
发布于 2010-08-13 17:14:39
使用OperationBindings:
http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/data/DataSource.html#setOperationBindings%28com.smartgwt.client.data.OperationBinding...%29
您可以在每个CRUD操作的基础上控制url来联系、HTTP方法和许多其他事情。
http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/data/DataSource.html#setDataURL(java.lang.String)
http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/data/DataSource.html#setDataProtocol%28com.smartgwt.client.types.DSProtocol%29
注意,要使用这些特定的HTTP谓词(PUT和DELETE),可以使用setRequestProperties和setHTTPMethod:
http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/data/DataSource.html#setRequestProperties%28com.smartgwt.client.data.DSRequest%29
http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/rpc/RPCRequest.html#setHttpMethod%28java.lang.String%29
但是请注意,一些较旧的浏览器不支持这些谓词。
https://stackoverflow.com/questions/3471260
复制相似问题