开发者

UIBinder and using event propogation

Prior to UIBinder in gwt, I wrapped elements in a HTMPanel which basically handled all the events for it开发者_如何学Gos child elements. So instead of attaching an eventlistener to multiple widgets, I just attached it to the parent container and used event bubbling. Can I do this in UIBinder? I know in the backing class for the yourclass.ui.xml, you can use UiHandler to handle event delegation but is this optimal? Am I still adding multiple listeners or is GWT doing something behind the scenes and attaching only 1 event handler.


You can add an HTMLPanel and attach handlers to it using UiBinder:

<g:HTMLPanel ui:field="myHtmlPanel">
  <h1>A Header</h1>
  <p>A Paragraph</p>
</g:HTMLPanel>

And then, in your view:

@UiField HTMLPanel myHtmlPanel;

...

@UiHandler("myHtmlPanel")
public void onClick(ClickEvent event) {
  // Handle the event.
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜