On 1 juil, 21:05, Jim <rightscr...@gmail.com> wrote:
> I have a question about the use of the Uibinder with regard to the
> simple binding of event handlers.
>
> From the examples in the - >>Developer's Guide - Event Handlers -
> section, it’s written:
>
> “Using anonymous inner classes as in the above example can use
> excessive memory for a large number of widgets, since it results in
> the creation of many handler objects. Instead of creating separate
> instances of the ClickHandler object for each widget that needs to be
> listened to, a single handler can be shared between many widgets.
> Widgets declare themselves as the source of an event when they invoke
> a handler method, allowing a single handler to distinguish between
> multiple event publishers with an event object's getSource() method.
> This makes better use of memory but requires slightly more code, as
> shown in the following example:”
>
> And then ... from the examples given in the ->>Declarative Layout with 
> UiBinder >>Simple binding of event handlers
>
> section, it’s written:
>
> “In a UiBinder owner class, you can use the @UiHandler annotation to
> have all of that anonymous class nonsense written for you.”
>
> Does this mean that when I use the Uibinder approach in GWT 2.0 that
> the excessive memory for a large number of widgets is now the result
> of this implementation?  Or is this drawback taken care of by the code
> generated by the GWT compiler?

UiBinder will generate a ClickHandler for each @UiHandler (at least
for now, it's been said it could change in the future).

> Or is there another way of coding the
> UiBinder and @UiHandler for these cases where a user-interface has
> many widgets ... say like many text input boxes?

You can code a single @UiHandler for your many input boxes and then
use the event's getSource within your method.

> Or perhaps, I'm wondering, with the speed of processors today, that
> this trade off for easy coding and readability offsets the slight loss
> in performance?  Is this the idea behind using UiBinders in this
> manner?

I think the idea is that UiBinder can do whatever it thinks is
necessary to make the code fast in most cases, it's just doing it for
now.
But the advice is more generally that you could also use event
delegation, i.e. register a single event handler at the Composite/
Widget level, which will receive the events of all child elements/
widgets (by way of "bubbling the DOM"), instead of attaching a handler
(even if it's the same handler) to each child element.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to