开发者

call click() function as programmatically in 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()


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜