setOptionsDataSource not working for SelectItem

Hello team,

I have a SelectItem in a form and I used setOptionDataSource on that SelectItem. The datasource is RPC datasource and so in the datasource i am making a service call to get the data from the backend. When I click on the AnalyisType dropdown it says Loading Data…and does not show the values. Can you please help?

  1. SmartGWT version -2.4 and Firefox-3.6;

  2.  MyDataSource datasource = new DataSource();
     DynamicForm form = new DynamicForm();
    
     final SelectItem analysisTypeItem = new SelectItem();   
     analysisTypeItem.setName("analysisType");   
     analysisTypeItem.setTitle("Select an Analysis Type");
     analysisTypeItem.setRequired(true);
     analysisTypeItem.setOptionDataSource(datasource);
    
     form.setFields(analysisTypeItem);
    
  3. MyDataSource constructor code below:


public MyDataSource() {
final DataSourceTextField analysisTypeField = new DataSourceTextField (“analysisType”, “Select an Analysis Type for this Transfer”);
analysisTypeField.setRequired(true);
analysisTypeField.setMultiple(false);

	service.getAnalysisType(new AsyncCallback<HashMap<String, String>>() {
		public void onFailure(Throwable caught) {
			GWT.log("Failed to get the studies");
		}
		public void onSuccess(HashMap<String, String> result) {
			analysisTypeField.setValueMap((LinkedHashMap<String, String>) result);
		}
	});

}

Thanks
BS

Recheck your initialization code …

You mean which code? Can you point out the specific line?

Thanks
BS

Hi Richardwasim,

I changed the DataSource code, instead of calling the following code in the constructor, I moved it to the fetch() method of the DataSource. Now the fetch method gets called and returning me the ‘result’ HashMap. Now how do I set the response?

service.getAnalysisType(new AsyncCallback<HashMap<String, String>>() {
public void onFailure(Throwable caught) {
GWT.log(“Failed to get the studies”);
}
public void onSuccess(HashMap<String, String> result) {
response.setData(result) //THIS IS NOT WORKING
//THIS IS ALSO NOT WORKING
response.getAttribute(“analysisType”).setValueMap(result);
}
});

I see the result being returned. Now what do I sent on the response?