views:

179

answers:

3

While creating a simple client for a REST service which I have stubbed out, I noticed that smartGWT's RestDataSource class is limited in the type of xml it can understand. All REST resources must respond with XML in the following format..

<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>

.. where the only variant is the someField/someOtherField tags.

This structure, which is little more than name/value pairs, is not going to work for us.

I then saw this demo on the SmartGWT showcase...

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

Which shows how to consume xml in an arbitrary format for display like so...

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();  
    }  

}  

This works well for GETs but how about PUTs, POSTs and DELETEs?

Can anyone share some code or point me to a resource which demonstrates how to do other RESTful operations from a SmartGWT client?

Thanks

A: 

I am using LGPL version of SmartGWT 2.1.I have used the above code but I am getting the following error.

"SmartClient can't directly contact URL 'http://rss.slashdot.org/Slashdot/slashdot' due to browser same-origin-policy. remove the host and port number (even if localhost) to avoid the problem, or use SJSONDataSource for JSONP protocol (which allows cross-site calls), or use the server-side HttpProxy included with SmartClient Server."

What should i do now?? I am really worried...

Regards Asad Naeem [email protected]