GWT UiHandler on HTMLPanel

brad picture brad · Apr 6, 2010 · Viewed 10.4k times · Source

I'm writing a widget with the following markup:

<g:HTMLPanel ui:field="shortcutPanel" styleName="{style.shortcut}">
    <g:Image ui:field="shortcutImage"></g:Image>
    <span ui:field="shortcutLabel"></span>
</g:HTMLPanel>

So essentially a div that wraps and image and a label. Now, instead of adding the event handlers on the image/span, I'd like an onClick to be associated with the HTMLPanel. My problem however is that gwt tells me that

shortcutPanel doesn't not have an addClickHandler method associated

So I'm assuming the difference is that HTMLPanel doesn't implement HasClickHandlers or something along that line. I'm wondering then what is the standard way to attach a click handler to a Ui element such as an HTMLPanel or even better, is there such a GWT Widget that is essentially a div wrapper that I can easily attach events to with the @UiHandler annotation.

Answer

Igor Klimer picture Igor Klimer · Apr 7, 2010

You are probably looking for FocusPanel - it has all the goodies: HasAllFocusHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasBlurHandlers, HasClickHandlers.... to name a few :) I find it to be the easiest and best way to attach click handlers to a Panel.