GWT UiHandler在HTMLPanel上 [英] GWT UiHandler on HTMLPanel

查看:113
本文介绍了GWT UiHandler在HTMLPanel上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

所以本质上是一个包裹和图像的div,一个标签。现在,而不是在图像/ span上添加事件处理程序,我希望一个onClick与HTMLPanel相关联。我的问题是,gwt告诉我,


shortcutPanel没有相关的addClickHandler方法


所以我假设不同之处在于HTMLPanel不实现 HasClickHandlers 或沿着该行的东西。我想知道什么是将点击处理程序附加到诸如HTMLPanel之类的Ui元素的标准方法是甚么更好,是否有这样的GWT Widget本质上是一个div包装器,我可以使用@UiHandler轻松地附加事件注释。

解决方案

您可能正在寻找 FocusPanel - 它有所有的好东西: HasAllFocusHandlers HasAllKeyHandlers HasAllMouseHandlers HasBlurHandlers HasClickHandlers ....要命名几个 :)我发现它是将点击处理程序附加到Panel的最简单和最佳方式。


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.

解决方案

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.

这篇关于GWT UiHandler在HTMLPanel上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆