i want to call click event function for Button in GWT... I tried this code but it is not working..
Button btnAddField = new Button();
btnAddField.setText("Add");
btnAddField.setWidth("225px");
btnAddField.addClickHandler(new btnAddFieldButtonClickListener());
private class btnAddFieldButtonClickListener implements ClickHandler{
public void onClick(ClickEvent event) {
Window.alert("Called Click Event");
}
}
this function wiil call at click the button
but it does not call when call this function btnAddField.click()
You can also try:
view.btnAddField.fireEvent(new ClickEvent() { } );
(It's a little hack, because com.google.gwt.event.dom.client.ClickEvent
has protected constructor.)
or
DomEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0,
false, false, false, false), view.btnAddField);
Then, in both cases, there's no need to create separate classes and break encapsulation for handlers in order to test click events.
I solve that problem by using this code
btnAddField.fireEvent(new ButtonClickEvent ())
private class ButtonClickEvent extends ClickEvent{
/*To call click() function for Programmatic equivalent of the user clicking the button.*/
}
It is working fine now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With