Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

Client-Side Applications

Even with regular server-side Vaadin applications, it may be useful to provide an off-line mode if the connection is closed. An off-line mode can persist data in a local store in the browser, thereby avoiding the need for server-side storage, and transmit the data to the server when the connection is again available. Such a pattern is commonly used with Vaadin TouchKit.

14.2. 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:

package com.example.myapp.client;

import com.google.gwt.core.client.EntryPoint; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.ui.RootPanel; import com.vaadin.ui.VButton;

public class MyEntryPoint implements EntryPoint { @Override

public void onModuleLoad() { // Create a button widget

Button button = new Button(); button.setText("Click me!"); button.addClickHandler(new ClickHandler() {

@Override

public void onClick(ClickEvent event) { mywidget.setText("Hello, world!");

}

}); RootPanel.get().add(button);

}

}

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

14.2.1. Module Descriptor

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

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE module PUBLIC

"-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd"> <module>

<!-- Builtin Vaadin and GWT widgets --> <inherits name="com.vaadin.Vaadin" />

<!-- The entry-point for the client-side application --> <entry-point class="com.example.myapp.client.MyEntryPoint"/>

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

Client-Side Module Entry-Point

353

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]