Go Back   SmartClient Forums > Smart GWT Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23rd Mar 2009, 07:28
alius alius is offline
Registered Developer
 
Join Date: Mar 2009
Posts: 193
Default GWT-RPC DataSource implementation

[from Isomorphic: we strongly recommend against using GWT-RPC for reasons listed in the FAQ. The approach is this thread should only be used as a temporary solution and only if you have a large set of pre-existing GWT-RPC services]

Hi All,
After some testing already provided GWT-RPC data source implementation (sticky post) (it was good starting point) I've decided to write my own. After reading post on how to implement Google Gears ( http://forums.smartclient.com/showthread.php?t=1192 ) I've realized that SmartClient already has possibility to use custom servers to load data. After checking SmartClient sources I've found protocol (which is not included in smartGWT) - "clientCustom". Using this protocol in data source allows to call custom server on data operations. It is done by overriding transformRequest method. When protocol is set to "clientCustom" - SmartClient after calling transformRequest method expects call of method processResponse after asynchronous call to server finishes.
The only thing is missing - possibility to set "clientCustom" protocol in smartGWT.
Here is what you can do:
- download smartGWT sources
- edit file main/src/com/smartgwt/client/types/DSProtocol.java - add these lines just after enumeration declaration :
Code:
    /**
     * dsRequest.data should be poplulated by custom call to server in transformRequest method. transformRequest should issue async request
     * to server and call processResponse on completion with created DSResponse object. If call was successful status and data should be filled.
     * If call was unsuccessful only status should contain error code.
     */
    CLIENTCUSTOM("clientCustom"),
- build your own smartGWT as it is described in http://code.google.com/p/smartgwt/wiki/BuildingFromSVN

I really hope that smartGWT developers will include it in future releases.

Please find attached implementation of GWT-RPC data source
Working example with real GWT RPC services I will upload in next response - can not upload more than 5 files.

Any comments are welcome.

Aleksandras
Attached Files
File Type: java GwtRpcDataSource.java (6.6 KB, 3097 views)

Last edited by Isomorphic; 10th Apr 2012 at 11:16..
Reply With Quote
  #2  
Old 23rd Mar 2009, 07:32
alius alius is offline
Registered Developer
 
Join Date: Mar 2009
Posts: 193
Default Working example of GWT-RPC data source.

Hi again.
As promised - uploading working example of GWT-RPC data source.

files in client package:
GwtRpcDataSource.java
TestDataSource.java
TestRecord.java
TestServiceAsync.java
TestService.java

files in server package:
TestServiceImpl.java

Aleksandras
Attached Files
File Type: java TestDataSource.java (6.3 KB, 3905 views)
File Type: java TestRecord.java (953 Bytes, 2504 views)
File Type: java TestService.java (512 Bytes, 2267 views)
File Type: java TestServiceAsync.java (586 Bytes, 2103 views)
File Type: java TestServiceImpl.java (2.2 KB, 2525 views)
Reply With Quote
  #3  
Old 23rd Mar 2009, 09:04
jasonzhang2002 jasonzhang2002 is offline
Registered Developer
 
Join Date: Feb 2009
Posts: 36
Default

This is a much clear implementation.


thanks

-jason
Reply With Quote
  #4  
Old 23rd Mar 2009, 09:18
hickum hickum is offline
Registered Developer
 
Join Date: Nov 2008
Posts: 8
Default

I agree this seems like a very clean approach... with the exception of having to alter the DSProtocol class.

Isomorphic -- any chance this will be included in a future build?
Reply With Quote
  #5  
Old 23rd Mar 2009, 09:34
jasonzhang2002 jasonzhang2002 is offline
Registered Developer
 
Join Date: Feb 2009
Posts: 36
Default

You may not need to recompile/rebuild. use this hack:
setAttribute("dataProtocol", "clientCustom", false);
in DataSource.

-jason
Reply With Quote
  #6  
Old 23rd Mar 2009, 09:46
hickum hickum is offline
Registered Developer
 
Join Date: Nov 2008
Posts: 8
Default

Sweet. Thanks.
Reply With Quote
  #7  
Old 23rd Mar 2009, 13:03
Isomorphic Isomorphic is online now
Administrator
 
Join Date: May 2006
Posts: 37,363
Default

Nice job Alius. Just FYI, those APIs (dataProtocol:"clientCustom" and the processResponse() method) were added to SmartClient precisely to enable GWT-RPC integration, but Alius was faster in creating a sample than we were :)

Relative to the other recently posted approach for GWT-RPC integration, the approach Alius has demonstrated has the advantage that paging could be implemented if the GWT-RPC service supports it.

One thing to correct - in TestDataSource.java it's assumed that a grid is initiating the requests. It would be more correct to use dsRequest.getOldValues() to get the originally submitted values (works with any component).
Reply With Quote
  #8  
Old 24th Mar 2009, 02:15
sjivan sjivan is offline
Registered Developer
 
Join Date: May 2008
Posts: 1,534
Default

The "clientCustom" enum has been added to DSProtocol in SVN.
Reply With Quote
  #9  
Old 24th Mar 2009, 06:13
alius alius is offline
Registered Developer
 
Join Date: Mar 2009
Posts: 193
Default Updated example.

Hi Isomorphic,

Thank you for correction.
Problem is that there is no method getOldValues() in DSRequest class (in smartGWT).

For the time being I've written my own version of combining original values with changes.

Please find an updated version of TestDataSource.java

Hi Sanjiv,

I've written some code which can be added to DSRequest to address this issue.
If you will find it suitable - please add it to next release.
Code:
    /**
    * The original record without changes.
    *
    * @param oldValues Original record without changes. Default value is null
    */
    public void setOldValues(ListGridRecord oldValues) {
        setAttribute("oldValues", oldValues);
    }
    /**
     * The original record without changes.
     *
     *
     * @return ListGridRecord
     *
     */
    public ListGridRecord getOldValues()  {
        JavaScriptObject oldValues = getAttributeAsJavaScriptObject ("oldValues");
        return new ListGridRecord (oldValues);
    }

    /**
     * Returns record where changes are combined with original values.
     *
     *
     * @return ListGridRecord
     */
    private ListGridRecord getEditedRecord () {
        // Retrieving values before edit
        JavaScriptObject oldValues = getAttributeAsJavaScriptObject ("oldValues");
        // Creating new record for combining old values with changes
        ListGridRecord newRecord = new ListGridRecord ();
        // Copying properties from old record
        JSOHelper.apply (oldValues, newRecord.getJsObj ());
        // Retrieving changed values
        JavaScriptObject data = getData ();
        // Apply changes
        JSOHelper.apply (data, newRecord.getJsObj ());
        return newRecord;
    }

Aleksandras
Attached Files
File Type: java TestDataSource.java (6.8 KB, 1020 views)
Reply With Quote
  #10  
Old 24th Mar 2009, 06:42
ebardet ebardet is offline
Registered Developer
 
Join Date: Nov 2008
Posts: 20
Default

Just reacting to
Quote:
the approach Alius has demonstrated has the advantage that paging could be implemented
Any reason why getStartRow returns an int where getEndRow returns an Integer? Or this is just a glitch.

Emmanuel
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


© 2010,2011 Isomorphic Software. All Rights Reserved