On Thursday, November 15, 2012 1:42:56 PM UTC+1, Ümit Seren wrote:
>
> I have some troubles understanding event bubbling and GWT. 
>
> Let's assume I have following structure: 
>
> <g:HTMLPanel>
>     <div>
>        <span>Text</span>
>    </div>
> </g:HTMLPanel>
>
> When I want to handle click events on the elements nested in the HTMLPanel 
> I add a DOM handler to the HTMLPanel: 
>
>
> HTMLPanel.addDomHandler(new ClickHandler() {
>
>     @Override
>     public void onClick(ClickEvent event) {
>         Element target = event.getNativeEvent().getEventTarget().cast();
>     }
>
> }, ClickEvent.getType());
>
> My expectation is that if I click on the the div element the onClickmethod is 
> called once with the target set to the 
> div element. If I click on the span element I expect the onClick method 
> to be called twice, once with the target set to div and another time set 
> to the span element. 
>
> However that doesn't work. When I click on the span element the onClickis 
> only called once with the target set to the 
> span element. Shouldn't the onClick method be called twice?
>
No.

The event is first dispatched on the span, where nobody listens to it. It 
then bubbles up to the div (currentEventTarget points to the div), where 
nobody listens either. Then again, it bubbles up to the HTMLPanel's div, 
where you listen to it. There, getEventTarget() is the span, and 
getCurrentEventTarget() is the HTMLPanel's getElement(). (and it continues 
bubbling that way up until the document, or until a handler calls 
stopPropagation())

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/omBwFmtOjUUJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to