SmartClient has advanced features for queuing multiple requests in one single request. This provides a mechanism for sending multiple requests to the server in a single HTTP turnaround, thus minimizing network traffic as well as allowing the server to treat multiple requests as a single transaction (if the server is able to do so). In this sample the previous sample will be refactored to add support for queuing and transaction support.
In order to work with this transaction request, the code created in DSRequest in the previous article needs to be used. The existing code in RPCManager will need to be refactored. As the transaction request is actually a list of DSRequest objects wrapped with additional information, it is necessary to parse and store the list of DSRequest objects. Then, for each DSRequest object, the execute() method is called (as shown in the previous sample) to get the DSResponse object which will be stored in a list for later use. Once all requests are processed, the DSResponse objects will be used to build and send back the response to the front-end. As a side note, a single DSRequest will also be handled by the same code.
Change the UI
You need to add the save button for the transaction progress.
width: 700, height: 224, alternateRecordStyles: true,
title: "Edit New",
title: "Save all",
Change the Gemfile
The smartclient gem v 0.0.5 supports the transaction progress method of the RPCManager helper class. You can get the methods from here or you can modify and add another methods after you build the gem from github.
gem "smartclient", "~> 0.0.5"
Processing the Request in the Controller
You need to request the smartclient json parameter from the post.
request = params[:smartclient]
# set the request parameters
rpc = RPCManager.new(request, Supplyitem)
@result = rpc.processRequest
render json: @result
By running rails server command, the application will start and a grid fetching and displaying the rows found in the table will be shown. (http://localhost:3000)
The complete code for this sample project can be downloaded from github.