On 8 sep, 16:37, John V Denley <[email protected]> wrote:
> I sitll cant work out from the code in this article, how to fire an
> event:
>
> final ListBox dropBox = new ListBox(false);
> dropBox.addItem("");
> dropBox.addItem("a");
> dropBox.addItem("b");
> dropBox.addItem("c");
> dropBox.addItem("d");
>
> dropBox.addChangeHandler(new ChangeHandler()
> {
> // �...@override
> public void onChange(ChangeEvent event)
> {
> switch (dropBox.getSelectedIndex()) {
> case 0:
> ApptPrice.setText("");
> break;
> case 1:
> ApptPrice.setText("8.50");
> break;
> case 2:
> ApptPrice.setText("9.50");
> break;
> case 3:
> ApptPrice.setText("10.50");
> break;
> case 4:
> ApptPrice.setText("11.50");
> break;
> default:
> ApptPrice.setText("should never see
> this");
> break;
>
> }
> }
> });
> dropBox.setItemSelected(setitemtoselect, true);
> dropBox.fireEvent(onChange);
>
> Its this last line I want to implement, Im setting the selection
> programattically (based on selections elsewhere in the code) and i
> need to fire the onChange event because as stated in the javadoc:
> "Note that setting the selection programmatically does not cause the
> ChangeHandler.onChange(ChangeEvent) event to be fired. "
Just keep a reference on your ChangeHandler and call its onChange
method directly (you can pass 'null' as the argument as you don't use
it):
ChangeHandler handler = new ChangeHandler () { ... }
dropBox.addChangeHandler(handler);
dropBox.setItemSelected(setitemtoselect, true);
handler.onChange(null);
If you really, really can't do that, then you can actually fire a
change event:
DomEvent.fireNativeEvent(Document.get().createChangeEvent(), dropBox);
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---