mmohab
mmohab

Reputation: 2383

GWT Handle User clicks on page

I am building a GWT application, and now I need to handle clicks for any component in the application to do some logic additional to the click logic.

e.g. is there is a button I would like to have onClick logic of the button be executed plus some additional global logic on all components.

Is there a way to register a global click event handler?

Upvotes: 0

Views: 276

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 122026

You can register a event like this for click

Event.addNativePreviewHandler(new NativePreviewHandler() {
    public void onPreviewNativeEvent(NativePreviewEvent event) {
        if (Event.as(event).getTypeInt() == Event.ONCLICK &&
            DOM.isOrHasChild(DOM.getElementById("buttonId"), Element.as(event.getEventTarget()))) {
            //Button was clicked.and notifys all elements clicks here
        }
    }
}

Upvotes: 2

Related Questions