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

SelectItem with Datasource and DefaultToFirst set to true

$
0
0
Hi,
I have a SelectItem bounded to a DataSource. I want my SelectItem to display the first item by default so I have called the setDefaultToFirstOption to true. Plus, I want to handle the selection of a item. Here is what I have so far.

Code:

final SelectItem templateCombo = new SelectItem();
templateCombo.setShowTitle(false);
templateCombo.setOptionDataSource(templateDS);
templateCombo.setDefaultToFirstOption(true);   
templateCombo.setName(name);
Criteria templateCriteria = new Criteria();
templateCriteria.addCriteria(criteria, value);
templateCombo.setPickListCriteria(templateCriteria);
     
templateCombo.addChangeHandler(new ChangeHandler() {
  public void onChange(ChangeEvent event) {
      String templateName = (String)event.getValue();
    }
});

The problem is that when the SelectItem fetches the data and select by default the first item, the onChange event is not called. The onChange event is only called from a user interaction. I need to handle the fact that the SelectItem has an item selected, even if it is selected by DefaultToFirstOption. Is there another event Handler instead of onChange that I can use that would be called when the selected value changed programmatically?

I have tried to call SelectItem.fetchData() directly with an DSCallback instead of auto fetching the data, to then get the selected value of do what I need to do, but my page does not load anymore when I manually call the fetchData method.

Thank you,
Dave

Viewing all articles
Browse latest Browse all 4756

Trending Articles