Click Events not getting attached

51 views
Skip to first unread message

gangurg gangurg

unread,
Oct 24, 2011, 9:05:34 PM10/24/11
to Google-We...@googlegroups.com
public class MyPanel extends AbsolutePanel implements HasClickHandlers {
    public MyPanel (Element elem) {
            super(elem.<com.google.gwt.user.client.Element> cast());
            onAttach();
           
    }

    @Override
    public HandlerRegistration addClickHandler(ClickHandler handler) {
            return addDomHandler(handler, ClickEvent.getType());
    }
}


//Some Widget
 HTMLPanel contentHtmlPanel = new HTMLPanel("Hello <a href=\"#world\">World</a>");
                    
                    
                   
                    MyPanel p = new MyPanel (contentHtmlPanel.getElement());
               p.addClickHandler(new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                         GWT.log("Hello World");
                        }
                      });
             
               
      

//Logic to mainuplate elemts inside a text area
com.google.gwt.dom.client.Text text =  
 txt.getParentElement().replaceChild(Element.as(p.getElement()), txt);

The Click handler works on Firefox but in IE the click handler is not getting attched . 

gangurg gangurg

unread,
Oct 25, 2011, 7:58:40 PM10/25/11
to Google-We...@googlegroups.com

Any thoughts on the question below ? On similar lines , How to retain Widgets Events after the widget is added as an Element .
I could add widget as an Element but loose the fact that  dont get events attached to the widget . Is there any work around for this ?

Jeff Larsen

unread,
Oct 26, 2011, 12:43:43 PM10/26/11
to google-we...@googlegroups.com, Google-We...@googlegroups.com
Why do you need to get widgets as elements? 

Why not just do 

p.add(new HTMLPanel("Hello <a href=\"#world\">World</a>");

Akash Gupta

unread,
Oct 26, 2011, 1:04:15 PM10/26/11
to google-we...@googlegroups.com
ya use them as widgets instead of elements,  if you want to retain the listeners.


--
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/-/1NyzCaMCB2QJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

gangurg gangurg

unread,
Oct 26, 2011, 2:30:32 PM10/26/11
to google-we...@googlegroups.com
How to use them as Widgets ?

Akash Gupta

unread,
Oct 27, 2011, 9:13:45 AM10/27/11
to google-we...@googlegroups.com
don't cast them into elements, use them as widgets, do not deal with elements at all.

Akash Gupta

unread,
Oct 27, 2011, 9:15:08 AM10/27/11
to google-we...@googlegroups.com
instead of   MyPanel p = new MyPanel (contentHtmlPanel.getElement());

do it   MyPanel p = new MyPanel (contentHtmlPanel);

and have a constructor accordingly.


Brandon Donnelson

unread,
Nov 5, 2011, 11:44:02 AM11/5/11
to google-we...@googlegroups.com, Google-We...@googlegroups.com
If your going to extend like this, you'll need to sink the events you want and then use OnBrowserEvent...

Brandon Donnelson

Thomas Broyer

unread,
Nov 5, 2011, 11:58:37 AM11/5/11
to google-we...@googlegroups.com, Google-We...@googlegroups.com


On Saturday, November 5, 2011 4:44:02 PM UTC+1, Brandon Donnelson wrote:
If your going to extend like this, you'll need to sink the events you want and then use OnBrowserEvent...

That's so old-school! addDomHandler(myHandler, ClickEvent.getType()) works equally well.

GWT Kid's problem here is to go down the DOM path without knowing how events work at the higher-level of widgets: http://code.google.com/p/google-web-toolkit/wiki/DomEventsAndMemoryLeaks

Brandon Donnelson

unread,
Nov 5, 2011, 12:04:41 PM11/5/11
to google-we...@googlegroups.com, Google-We...@googlegroups.com
Good point :)
Reply all
Reply to author
Forward
0 new messages