Using HTMLPanel's containing <div> HTML event attribut

GWT Designer allows you to quickly create the modules, composites, panels, remote services and other elements that comprise Google Web Tookit applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Using HTMLPanel's containing <div> HTML event attribut

Postby japolzin » Wed May 09, 2007 12:06 pm

I have a HTMLPanel that contains html text like

<div onclick="onclick(event);">foo</div>

but I have no luck getting the client side to fire off the onclick HTML event attribute when the <div> element is clicked on.

I have defined a onclick(Event e) method in my primary EntryPoint class but the mouse event is never delivered.

I have tried using a FocusPanel to contain the HTMLPanel and do get click events for the panel but I am not sure how to find the element that was clicked on. This would certainly be a better approach.

Any ideas.


Posts: 1
Joined: Sat May 05, 2007 6:48 pm

Re: Using HTMLPanel's containing <div> HTML event attr

Postby Eric Clayberg » Thu May 10, 2007 5:32 am

It appears that you are trying to work with GWT as if it were a normal JavaScript application.

To handle events the way you want, method DOM.setEventListener should be used.

Something like this should work:

Code: Select all
public class ImageViewer implements EntryPoint {
   private Button clickMeButton;
   public void onModuleLoad() {
      RootPanel rootPanel = RootPanel.get();
      clickMeButton = new Button();
      rootPanel.add(clickMeButton, 276, 179);
      clickMeButton.setText("Click me!");
      clickMeButton.addClickListener(new ClickListener() {
         public void onClick(Widget sender) {
            Window.alert("Hello, GWT World!");
      HTMLPanel panel = new HTMLPanel("<div>foo</div>");
      panel.sinkEvents(Event.FOCUSEVENTS | Event.ONCLICK | Event.ONBLUR);
      panel.setSize("100px", "30px");
      rootPanel.add(panel, 10, 10);
      DOM.setEventListener(panel.getElement(), new EventListener() {
         public void onBrowserEvent(Event event) {
            System.out.println("onBrowserEvent: " + DOM.eventGetTypeString(event));

BTW, general GWT how-to questions like this should be posted to Google's GWT forum.
Eric Clayberg
Software Engineering Manager

Author: "Eclipse Plug-ins"
Eric Clayberg
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Return to GWT Designer

Who is online

Users browsing this forum: No registered users and 3 guests