I’m trying to create a dynamic form using a datasource. The datasource gets all the form field using an RPC call (shown below).
public PublishedReportParameterDS(String id,String reportId) {
setID(id);
if (service == null) {
service = WebAnalyticsRemoteService.Util.getInstance();
}
service.getHeaders(reportId,new AsyncCallback<List<HeaderGWT>>() {
public void onFailure(Throwable caught) {
SC.say("There was an error fetching data from the server");
}
public void onSuccess(List<HeaderGWT> result) {
final List<DataSourceField> items = new ArrayList<DataSourceField>();
for(HeaderGWT record:result){
DataSourceTextField filterValueField = new DataSourceTextField(record.getName()+"filterValue","filterValue",100,false);
items.add(filterValueField);
}
DataSourceField[] dsFields = new DataSourceField[items.size()];
setFields( items.toArray(dsFields));
}
});
}
It only works when I move the RPC call and field creating logic to my canvas code.
service.getHeaders(reportId,new AsyncCallback<List<HeaderGWT>>() {
public void onFailure(Throwable caught) {
SC.say("There was an error fetching data from the server");
}
public void onSuccess(List<HeaderGWT> result) {
for(HeaderGWT record:result){
TextItem filterValue = new TextItem();
filterValue.setName(record.getName()+"filterValue");
filterValue.setShowTitle(false);
items.add(filterValue);
}
FormItem[] fitems = new FormItem[items.size()];
Is my approach to use datasource for the dynamic field generation not right?
Also, Any guidance on how to pass the filled form parameters to my RPC Datasource would be appreciated. In the past, I have set the form values to an attribute in the datasource class which was referenced in the RPC Datasource that set the parameters to be passed on to servlet.
Thanks,
Jyot