Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call click() function as programmatically in GWT

Tags:

gwt

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()

like image 360
Kandha Avatar asked Oct 20 '10 05:10

Kandha


2 Answers

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.

like image 80
omnomnom Avatar answered Nov 15 '22 11:11

omnomnom


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.

like image 38
Kandha Avatar answered Nov 15 '22 11:11

Kandha