Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Multiple update on a rest service

    Hi,

    I am using SmartGWT LGPL client version (2.4), and a tomcat server, with Spring.
    I'd like to integrate a rest spring server with your Datasource.
    I also need that all edits (of a ListGrig) are sent togheter in a single browser request.

    According to RPCManager Javadoc, I wrote:

    Code:
    IButton save = new IButton("Save", new ClickHandler() {
    			
    	@Override
    	public void onClick(ClickEvent event) {
    		
    		RPCManager.startQueue();
    		ordersGrid.saveAllEdits();
    		RPCManager.sendQueue();
    	}
    });
    But the queue doesn't seem to work. When I press the "Save" button, the RPCManager sends one post for each edited row.
    Does queueing system works with the LGPL client?
    Because I read that RestDatasource doesn't work with queues, I extended directly the DataSource class, and wrote this:

    Code:
    public class OrdersDS extends DataSource {
    
    	public static final OrdersDS INSTANCE = new OrdersDS();
    
    	private OrdersDS() {
    		super();
    		setID("orders");
    		setDataFormat(DSDataFormat.JSON);
    		setRecordXPath("/response/data");
    		
    		//Configuration code omitted...
            
            OperationBinding fetch = new OperationBinding();
            fetch.setOperationType(DSOperationType.FETCH);  
            fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
            fetch.setDataTransport(RPCTransport.XMLHTTPREQUEST);
            fetch.setDataURL("http://localhost:8080/myapp/dsrest/orders/fetch.json");
            fetch.setDataFormat(DSDataFormat.JSON);
            
            OperationBinding update = new OperationBinding();  
            update.setOperationType(DSOperationType.UPDATE);
            update.setDataProtocol(DSProtocol.POSTMESSAGE);
            update.setDataTransport(RPCTransport.XMLHTTPREQUEST);
            update.setDataURL("http://localhost:8080/myapp/dsrest/orders/update.json");
            update.setDataFormat(DSDataFormat.JSON);
            
            setOperationBindings(fetch,update);
    	}
    	
    	@Override
    	protected Object transformRequest(DSRequest dsRequest) {
    		dsRequest.setContentType("application/json; charset=utf-8");
    		
    		super.transformRequest(dsRequest);
    		
    		return JSON.encode(dsRequest.getData());
    	}
    }

    Assuming that queueing system doesn't work, I tryed to extend the Datasource (RestDatasource this time) and try to override some methods,
    like update(). But it seems that overrinding methods other than transformRequest(...) and transformeResponse(...) (and a few others) does NOT work.

    Is there a proper way to extend DataSource and in general SmartGWT classes? Note that overriding transformRequest(...) and transformeResponse(...)
    is not enough to create a personal way for queueing operations.

    Finally, is there any way to write a custom RPCManager?

    Thanks for your attention.

    #2
    See this thread for some info on a queuing rest datasource. If your server expects a single hierarchical data structure for saving the grid (like master/detail) take a look at this SmartClient article for saving all grid edits as a single request.

    Comment


      #3
      I have found out that by using DSProtocol.CLIENTCUSTOM in many points (in setDataProtocol(...) of DataSource and in the OperationBinding ) you can convince the DataSource not to send requests to the server.
      You can than take control of the DataSource extending transformRequest(DSRequest dsRequest) and using processResponse(...), as the documentation of DSProtocol.CLIENTCUSTOM states.

      All the threads I have read didn't say how to write a personal DataSource with all the features you need.

      Comment

      Working...
      X