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

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.

14.3. Compiling and Running a Client-Side Application

Compilation of client-side modules other than widget sets with the Vaadin Plugin for Eclipse has recent changes and limitations at the time of writing of this edition and the information given here may not be accurate.

The application needs to be compiled into JavaScript to run it in a browser. For deployment, and also initially for the first time when running the Development Mode, you need to do the compilation with the Vaadin Client Compiler, as described in Section 13.4, “Compiling a Client-Side Module”.

During development, it is easiest to compile with the Development Mode, which also allows debugging when you run it in debug mode in an IDE. To launch it, you need to execute the com.google.clientside.dev.DevMode class in the Vaadin JAR with the parameters such as the following:

-noserver -war WebContent/clientside com.example.myapp.MyModule -startupUrl http://localhost:8080/myproject/loaderpage.html -bindAddress 127.0.0.1

See Section 13.6.1, “Launching Development Mode” for a description of the parameters. The startupUrl should be the URL of the host page described in Section 14.4, “Loading a ClientSide Application”.

In Eclipse, you can create a launch configuration to do the task, for example by creating it in the Vaadin section of project preferences and then modifying it appropriately.

The parameter for the -war should be a path to a deployment folder that contains the compiled client-side module, in Eclipse under WebContent.

14.4. Loading a Client-Side Application

You can load the JavaScript code of a client-side application in an HTML host page by including it with a <script> tag, for example as follows:

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Embedding a Vaadin Application in HTML Page</title>

<!-- Load the Vaadin style sheet --> <link rel="stylesheet"

type="text/css" href="/myproject/VAADIN/themes/reindeer/legacy-styles.css"/>

</head>

<body>

<h1>A Pure Client-Side Application</h1>

<script type="text/javascript" language="javascript" src="clientside/com.example.myapp.MyModule/

354

Compiling and Running a Client-Side Application

Client-Side Applications

com.example.myapp.MyModule.nocache.js">

</script>

</body>

</html>

The JavaScript module is loaded in a <script> element.The src parameter should be a relative link from the host page to the compiled JavaScript module.

If the application uses any supplementary Vaadin widgets, and not just core GWT widgets, you need to include the Vaadin theme as was done in the example. The exact path to the style file depends on your project structure - the example is given for a regular Vaadin application where themes are contained in the VAADIN folder in the WAR.

In addition to CSS and scripts, you can load any other resources needed by the client-side application in the host page.

Loading a Client-Side Application

355

356

Chapter 15

Client-Side

Widgets

15.1. Overview ..............................................................................................

357

15.2. GWT Widgets ......................................................................................

358

15.3. Vaadin Widgets ....................................................................................

358

This chapter gives basic documentation on the use of the Vaadin client-side framework for the purposes of creating client-side applications and writing your own widgets.

This topic is new in the book. Unfortunately, because of pressing release schedules, we were unable to give as much detail as the topic demanded. The Vaadin features for client-side development are also evolving rapidly, so some of the content may already be outdated. The chapter will be expanded in the future with more up-to-date information.

15.1. Overview

The Vaadin client-side API is based on the Google Web Toolkit. It involves widgets for representing the user interface as Java objects, which are rendered as a HTML DOM in the browser. Events caused by user interaction with the page are delegated to event handlers, where you can implement your UI logic.

In general, the client-side widgets come in two categories - basic GWT widgets and Vaadinspecific widgets. The library includes connectors for integrating the Vaadin-specific widgets with the server-side components, thereby enabling the server-side development model of Vaadin. The integration is described in Chapter 16, Integrating with the Server-Side.

Book of Vaadin

357

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