It sounds like you're using an HTML-based binder, not a Widget binder, so
your createAndBindUi would produce an Element that your class can set as
its DOM representation (I usually make my class extend Element - for some
reason the Eclipse wizard wants to make it a UiObject). And, then, as
another poster mentioned, you can have SpanElement, DivElement, etc., in
the Java class to match what's in the xml. So, you shouldn't have to cast
to element, the pieces should already be some sort of Element.
I'm pretty sure @UiHandler won't work for an HTML-based binder, since the
Java fields aren't widgets.
I haven't tried your approach for hooking up handlers, but have used a
delegating approach - the Java class, as a Widget, can have a regular click
handler, which can then look at the target of the event and decide what to
do accordingly (like fire off a custom event that represents whatever
clicking the element meant).
On Thursday, August 15, 2013 3:59:48 PM UTC-4, 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
> }
> });
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.