Hi,
You would normally use fireNativeEvent in testing code and usually are
better off refactoring your UI code to avoid it in user code; however,
if you do want to use it, then you need to move completely to the new
event system.
For example, to programmatically click a Button you could write
something simple like this to create a Button and a ClickHandler:
Button button = new Button("Sign In");
RootPanel.get().add( button);
HandlerRegistration h = button.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
Window.alert("Button Clicked");
}
})
Now you will have a button in the DOM and a ClickHandler attached to
it. To fire an event programmatically, you would use
DomEvent.fireNativeEvent method which needs you to create an event
through the DOM document and apply it to widget that implements the
appropriate handler - in this case Button implements HasClickHandlers,
we've added a ClickHandler, so we can fire a click event as follows:
a) Get the current DOM Document, i.e. Document doc =
com.google.gwt.dom.client.Document.get();
b) Create a click event in that document, e.g. NativeEvent evt =
doc.createClickEvent(0, 0, 0, 0, 0, false, false, false, false); (you
can read the JavaDoc to see all the arguments' meanings)
c) Fire that event on your Button, i.e. DomEvent.fireNativeEvent(evt,
button);
Hope that helps,
Adam
On 15 Maj, 01:43, rjcarr <[email protected]> wrote:
> I don't often fire off programmatic events but there are a couple
> cases where I need to and I can't figure out how to make it happen
> since I've been transition to 1.6.
>
> Before, as an example, I'd have something like this:
>
> class MyClass implements ClickListener {
> public MyClass() {
> Button b = new Button("", this);
> onClick(b); // programmatic click
> }
>
> public void onClick(Widget w) { ... }
>
> }
>
> But now in 1.6 I'm not sure how to make this happen. Looking at
> creating my own ClickEvent object the constructor, says this:
>
> "Protected constructor, use DomEvent.fireNativeEvent
> (com.google.gwt.dom.client.NativeEvent,
> com.google.gwt.event.shared.HasHandlers) to fire click events."
>
> But looking up that method I can't figure out what it is asking for.
> Could someone help me out with an example?
>
> I searched through all the samples but nobody ever calls
> fireNativeEvent. Thanks!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---