Hello, everybody
I'm using SmartGWT 2.1. The underlying data (Oracle database) have changed and I need to tell the SelectItem control to update its options.
I tried DataSource.invalidateCaches but it does not work. Commenting out setClientOnly(true) does not help either.
Could you help me on this? Below are the code snippets and please tell me if there is anything unclear. (The general idea of the code is that, there is a SelectItem in the guideform to select a "template"; now a new "template" is added by the user, the SelectItem need to fetch the data again to see the changes.)
Regards,
Warren Tang
I'm using SmartGWT 2.1. The underlying data (Oracle database) have changed and I need to tell the SelectItem control to update its options.
I tried DataSource.invalidateCaches but it does not work. Commenting out setClientOnly(true) does not help either.
Could you help me on this? Below are the code snippets and please tell me if there is anything unclear. (The general idea of the code is that, there is a SelectItem in the guideform to select a "template"; now a new "template" is added by the user, the SelectItem need to fetch the data again to see the changes.)
Code:
//This is the guideform: public class GuideForm extends HLayout public GuideForm() { ... ... templateItem = new SelectItem("template", "select a template"); templateItem.setOptionDataSource(BasicOptionDataSource .getInstance("GUIDETEMPLATE")); templateItem.setRedrawOnChange(true); templateItem.setValueField("value"); templateItem.setDisplayField("display"); templateItem.setWidth("*"); ... ... }
Code:
//This is the datasource: public class BasicOptionDataSource extends DataSource public BasicOptionDataSource(String category) { this.category = category; setDataProtocol(DSProtocol.CLIENTCUSTOM); setDataFormat(DSDataFormat.CUSTOM); setID(category + "__OptionDS"); DataSourceTextField valueField = new DataSourceTextField("value", "value"); valueField.setPrimaryKey(true); valueField.setRequired(true); DataSourceTextField displayField = new DataSourceTextField("display", "display"); setFields(valueField, displayField); setClientOnly(true); //setCacheAllData(true); } protected void executeFetch(final String requestId, final DSRequest request, final DSResponse response) { UtilService.Util.getInstance().getOptions(category, new AsyncCallback<List<OptionItem>>() { @Override public void onSuccess(List<OptionItem> result) { List<ListGridRecord> records = new ArrayList<ListGridRecord>(); addTo(result, records); response.setData(records.toArray(new ListGridRecord[0])); response.setTotalRows(result.size()); processResponse(requestId, response); } @Override public void onFailure(Throwable caught) { response.setStatus(RPCResponse.STATUS_FAILURE); processResponse(requestId, response); } private void addTo(List<OptionItem> result, List<ListGridRecord> records) { for (OptionItem service : result) { ListGridRecord record = new ListGridRecord(); record.setAttribute("value", service.getValue()); record.setAttribute("display", service.getDisplay()); records.add(record); } } }); }
Code:
//The underlining data are changed (a new template is added) //so I need to update the options in SelectItem public class GuideTemplateForm extends HLayout private void initHandlers() { insertBtn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (!dynamicForm.validate()) { return; } GuideTemplate template = getData(); BaseMgtService.Util.getInstance().insertGuideTemplate( template, new AsyncCallback<Void>() { @Override public void onSuccess(Void result) { Tab tab = MyTabSet.getInstance() .getSelectedTab(); MyTabSet.getInstance().removeTab(tab); String tabId = MyTabSet.TAB_GUIDETEMPLATE_MANAGEMENT; Tab tab1 = MyTabSet.getInstance().getTab(tabId); if (tab1 != null) { tab1.getPane().redraw(); MyTabSet.getInstance().selectTab(tab1); } //Tried to invalidate the cache but failed BasicOptionDataSource.getInstance("GUIDETEMPLATE").invalidateCache(); } @Override public void onFailure(Throwable caught) { MessengerHelper.error(caught.getMessage()); } }); } });
Warren Tang
Comment