Tuesday, August 27, 2013

Re: Correct way to sink events on UiBinder Element

Thomas,

Thanks for the heads up about the leak. How would I use "uibinder for
cells" if I am just creating a standard Composite-based widget?

What would an event delegation path look like at the composite level?
Do I just sink the events on this.getElement() and then check if the
event target is my UiField Element?


On Mon, Aug 19, 2013 at 7:59 AM, Thomas Broyer <t.broyer@gmail.com> wrote:
>
>
> On Thursday, August 15, 2013 9:59:48 PM UTC+2, Shaun Tarves wrote:
>>
>> I am defining several elements via UiBinder. My understanding is these are
>> created as com.google.gwt.dom.client.Element during the createAndBind call.
>>
>> I would like to add a click handler to one of these elements. Is there any
>> way other than casting those to com.google.gwt.dom.client.Element like this?
>>
>>
>> @UiField
>> Element clickable;
>>
>> DOM.sinkEvents((com.google.gwt.user.client.Element) clickable,
>> Event.ONCLICK);
>> DOM.setEventListener((com.google.gwt.user.client.Element) clickable, new
>> EventListener() {
>> public void onBrowserEvent(Event event) {
>> //TODO: Some code
>> }
>> });
>
>
> Don't do that, you might leak memory on some browsers (aka, do it at your
> own risks)
>
> Either use widgets or use the event delegation pattern, where your widget
> listens to events and do one thing or another depending on the event's type
> and target.
> For event delegation, using "uibinder for cells" makes it easier as you can
> use @UiHandler and let the generator do the routing for you.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Google Web Toolkit" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/google-web-toolkit/6bJbRxKmh08/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> google-web-toolkit+unsubscribe@googlegroups.com.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> Visit this group at http://groups.google.com/group/google-web-toolkit.
> For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment