Client-Side Module Entry-Point

A client-side application requires an entry-point where the execution starts, much like the init() method in server-side Vaadin UIs.

Consider the following application:

  1. package com.example.myapp.client;
  2. import com.google.gwt.core.client.EntryPoint;
  3. import com.google.gwt.event.dom.client.ClickEvent;
  4. import com.google.gwt.event.dom.client.ClickHandler;
  5. import com.google.gwt.user.client.ui.RootPanel;
  6. import com.vaadin.ui.VButton;
  7. public class MyEntryPoint implements EntryPoint {
  8. @Override
  9. public void onModuleLoad() {
  10. // Create a button widget
  11. Button button = new Button();
  12. button.setText("Click me!");
  13. button.addClickHandler(new ClickHandler() {
  14. @Override
  15. public void onClick(ClickEvent event) {
  16. mywidget.setText("Hello, world!");
  17. }
  18. });
  19. RootPanel.get().add(button);
  20. }
  21. }

Before compiling, the entry-point needs to be defined in a module descriptor, as described in the next section.

Module Descriptor

The entry-point of a client-side application is defined, along with any other configuration, in a client-side module descriptor, described in “Client-Side Module Descriptor”. The descriptor is an XML file with suffix .gwt.xml.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE module PUBLIC
  3. "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN"
  4. "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
  5. <module>
  6. <!-- Builtin Vaadin and GWT widgets -->
  7. <inherits name="com.vaadin.Vaadin" />
  8. <!-- The entry-point for the client-side application -->
  9. <entry-point class="com.example.myapp.client.MyEntryPoint"/>
  10. </module>

You might rather want to inherit the com.google.gwt.user.User to get just the basic GWT widgets, and not the Vaadin-specific widgets and classes, most of which are unusable in pure client-side applications.

You can put static resources, such as images or CSS stylesheets, in a public folder (not a Java package) under the folder of the descriptor file. When the module is compiled, the resources are copied to the output folder. Normally in pure client-side application development, it is easier to load them in the HTML host file or in a ClientBundle (see GWT documentation), but these methods are not compatible with server-side component integration, if you use the resources for that purpose as well.