I have been told that I can use Dynamic DataSources via the DynamicDSGenerator interface. I would like to use this because my server will be responding to requests for data where the actual DataSource description will not known until the server processes the request. As I'm new to SmartGWT it would be really helpful if there was a complete client/server example of something similar to this. I could not find anything in the Smart GWT showcase. I previously asked a similar question (http://forums.smartclient.com/showthread.php?t=19229) but the response was insufficient for me to continue my evaluation.
Announcement
Collapse
No announcement yet.
X
-
The DynamicDSGenerator interface has the API
Code:DataSource getDataSource(java.lang.String id, DSRequest dsRequest)
Hope this helps.
-
Thanks. This is definitely helpful. So this is the server-side showing how to create a dynamic datasource. If possible, can you speak a bit about how this correlates to the client side? Once I create this server side DataSource, how do I communicate that back to the client so that it can assign this DataSource to a databound component like a TreeGrid which will then presumably ask the server for the actual data?
Comment
-
This DynamicDSGenerator API gets called by the framework when looking up a datasource by ID. This is mentioned in the javadocs of DynamicDSGenerator
Comment
-
I have been searching example for dynamic datasource for a while. In my case I send query parameters to the php file (REST). The number of field and type in the response is not known.
What I need is transform this response into datasource, however I could not find any example. If you point any example I really appreciate..
Comment
-
I am not sure if this is the best approach but at least a solution.
Code:OperationBinding fetch = new OperationBinding(); fetch.setOperationType(DSOperationType.FETCH); fetch.setDataProtocol(DSProtocol.POSTPARAMS); this.setOperationBindings(fetch); this.setDataFormat(DSDataFormat.JSON); this.setFetchDataURL("php/clilead/clilead.php"); /* Read Data */ String str1; DataSourceTextField tmp = null; DataSourceIntegerField tint = null; /* */ /* data array have to be defined and completed before this call */ /* */ for(int i=0; i<data.length; i=i+1) { str1 = data[i].getAttribute("dbfield"); // Database field if (str1.equals("fl_id")) { // This field is guarantee and primary index tint = new DataSourceIntegerField(str21, str1, 150); tint.setPrimaryKey(true); this.addField(tint); } else { tmp = new DataSourceTextField(str1, str1, 150); this.addField(tmp); } } } /* Her is how I get the data array*/ RestDataSource dsFields = new dsFields(); Criteria crt = new Criteria(); crt.addCriteria("uname", uname); dsFields.fetchData(crt, new DSCallback() { public void execute(DSResponse response, Object rawData, DSRequest request) { data = response.getData(); } });
Hope it helps to someone.
Comment
Comment