You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

clientsideapp-entrypoint.asciidoc 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ---
  2. title: Client-Side Module Entry-Point
  3. order: 2
  4. layout: page
  5. ---
  6. [[clientsideapp.entrypoint]]
  7. = Client-Side Module Entry-Point
  8. A client-side application requires an __entry-point__ where the execution
  9. starts, much like the [methodname]#init()# method in server-side Vaadin UIs.
  10. Consider the following application:
  11. [source, java]
  12. ----
  13. package com.example.myapp.client;
  14. import com.google.gwt.core.client.EntryPoint;
  15. import com.google.gwt.event.dom.client.ClickEvent;
  16. import com.google.gwt.event.dom.client.ClickHandler;
  17. import com.google.gwt.user.client.ui.RootPanel;
  18. import com.vaadin.ui.VButton;
  19. public class MyEntryPoint implements EntryPoint {
  20. @Override
  21. public void onModuleLoad() {
  22. // Create a button widget
  23. Button button = new Button();
  24. button.setText("Click me!");
  25. button.addClickHandler(new ClickHandler() {
  26. @Override
  27. public void onClick(ClickEvent event) {
  28. mywidget.setText("Hello, world!");
  29. }
  30. });
  31. RootPanel.get().add(button);
  32. }
  33. }
  34. ----
  35. Before compiling, the entry-point needs to be defined in a module descriptor, as
  36. described in the next section.
  37. [[clientsideapp.entrypoint.descriptor]]
  38. == Module Descriptor
  39. The entry-point of a client-side application is defined, along with any other
  40. configuration, in a client-side module descriptor, described in
  41. <<../clientside/clientside-module#clientside.module,"Client-Side
  42. Module Descriptor">>. The descriptor is an XML file with suffix
  43. [filename]#.gwt.xml#.
  44. [source, xml]
  45. ----
  46. <?xml version="1.0" encoding="UTF-8"?>
  47. <!DOCTYPE module PUBLIC
  48. "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN"
  49. "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
  50. <module>
  51. <!-- Builtin Vaadin and GWT widgets -->
  52. <inherits name="com.vaadin.Vaadin" />
  53. <!-- The entry-point for the client-side application -->
  54. <entry-point class="com.example.myapp.client.MyEntryPoint"/>
  55. </module>
  56. ----
  57. You might rather want to inherit the [classname]#com.google.gwt.user.User# to
  58. get just the basic GWT widgets, and not the Vaadin-specific widgets and classes,
  59. most of which are unusable in pure client-side applications.
  60. You can put static resources, such as images or CSS stylesheets, in a
  61. [filename]#public# folder (not a Java package) under the folder of the
  62. descriptor file. When the module is compiled, the resources are copied to the
  63. output folder. Normally in pure client-side application development, it is
  64. easier to load them in the HTML host file or in a [classname]#ClientBundle# (see
  65. GWT documentation), but these methods are not compatible with server-side
  66. component integration, if you use the resources for that purpose as well.