Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

How to add a callback to the fetch fired from option datasource

$
0
0
I am trying to get the loaded data(Record objects) in a Comboboxitem. I set an option data source to the combobox item.
Now according the Formitem.optionDatasource documentation,

The data will be retrieved via a "fetch" operation on the DataSource, passing the pickListCriteria (if set) as criteria, and passing optionFilterContext (if set) as DSRequest properties.


I wanted to know is there any way i can add a callback to the above fetch operation that was fired during init,so that i can have the records that are loaded into the combobox ?

I am asking this because, when user selects a record from comboboxitem, i want to extract the selected record (Record object) so that i get pull other attributes apart from displayFiled and valueField.

I tried to achieve this via event.getItem().getSelectedRecord() , however again the doc's says that return value for the method getSelectedRecord will be null until the fetch completes( in which case how can i get the record) or there is no match.

Code:

ComboBoxItem selectFileItem = new ComboBoxItem("fileSelect", "ComboBox");
                selectFileItem.setAutoFetchData(true);
                selectFileItem.setHideEmptyPickList(false);
                selectFileItem.setAddUnknownValues(Boolean.FALSE);
                selectFileItem.setWrapTitle(false);
                selectFileItem.setRequired(true);
                selectFileItem.setColSpan(5);
                selectFileItem.setWidth(745);
                selectFileItem.setOptionDataSource(myOptionDataSource);
                selectFileItem.setValueField(myOptionDataSource.KEY);
                selectFileItem.setDisplayField(myOptionDataSource.DESCRIPTION);

selectFileItem.addChangeHandler(new ChangeHandler() {
                       
@Override
public void onChange(ChangeEvent event) {
  event.cancel();
  if(event.getValue() != null) {
    Record record = event.getItem().getSelectedRecord(); // this line is returning null
......
                        }
}


SmartClient version:
SC_SNAPSHOT-2011-12-05/LGPL Development Only (built 2011-12-05)
Browser : Chorme 32.0.1

Viewing all articles
Browse latest Browse all 4756

Trending Articles