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