Vaadin

Join Vaadin Log In

This section gives instructions for creating a new Eclipse project using the Vaadin Plugin. The task will include the following steps:

  1. Create a new project

  2. Write the source code

  3. Configure and start Tomcat (or some other web server)

  4. Open a web browser to use the web application

We also show how you can debug the application in the debug mode in Eclipse.

This walkthrough assumes that you have already installed the Vaadin Plugin and set up your development environment, as instructed in Section 2.1.1, “Installing the Distribution Package” and Section 2.2, “Setting up the Development Environment”.

Let us create the first application project with the tools installed in the previous section. First, launch Eclipse and follow the following steps:

  1. Start creating a new project by selecting from the menu FileNewProject....
  2. In the New Project window that opens, select WebVaadin Project and click Next.
  3. In the Vaadin Project step, you need to set the basic web project settings. You need to give at least the project name and the runtime; the default values should be good for the other settings.

    Project name

    Give the project a name. The name should be a valid identifier usable cross-platform as a filename and inside a URL, so using only lower-case alphanumerics, underscore, and minus sign is recommended.

    Use default

    Defines the directory under which the project is created. You should normally leave it as it is. You may need to set the directory, for example, if you are creating an Eclipse project on top of a version-controlled source tree.

    Target runtime

    Defines the application server to use for deploying the application. The server that you have installed, for example Apache Tomcat, should be selected automatically. If not, click New to configure a new server under Eclipse.

    Configuration

    Select the configuration to use; you should normally use the default configuration for the application server. If you need to modify the project facets, click Modify.

    Deployment configuration

    This setting defines the environment to which the application will be deployed, to generate the appropriate project directory layout and configuration files. The choises are:

    • Servlet (default),
    • Google App Engine Servlet, and
    • Generic Portlet (Portlet 2.0).
    • Old Portlet (Portlet 1.0).

    The further steps in the New Project Wizard depend on the selected deployment configuration; the steps listed in this section are for the default servlet configuration. See Section 11.9, “Google App Engine Integration” and Section 11.8, “Portal Integration” for details on the use of Vaadin in the alternative environments.

    Vaadin version

    Select the Vaadin version to use. The drop-down list shows, by default, the latest available version of Vaadin. If you want to use another version, click Download. The dialog that opens lists all official releases of Vaadin.

    If you want to use a pre-release version or a nightly development build, select Show pre-release versions and nightly builds. Select a version and click Ok to download it. It will appear as a choise in the drop-down list.

    If you want to change the project to use another version of Vaadin, for example to upgrade to a newer one, you can go to project settings and download and select the other version.

    You can click Finish here to use the defaults for the rest of the settings, or click Next.

  4. The settings in the Web Module step define the basic servlet-related settings and the structure of the web application project. All the settings are pre-filled, and you should normally accept them as they are.

    Context Root

    The context root (of the application) identifies the application in the URL used for accessing it. For example, if the server runs in the apps context and the application has myproject context, the URL would be http://example.com/app/url. The wizard will suggest myproject for the context name.

    Content Directory

    The directory containing all the content to be included in the servlet and served by the web server. The directory is relative to the root directory of the project.

    Java Source Directory

    The default source directory containing the application sources. The src directory is suggested; another convention common in web applications is to use WebContent/WEB-INF/src, in which case the sources are included in the servlet (but not served in HTTP requests).

    Generate deployment descriptor

    Should the wizard generate the web.xml deployment descriptor required for running the servlet in the WebContent/WEB-INF directory. Strongly recommended. See Section 4.8.3, “Deployment Descriptor web.xml for more details.

    This will be the sub-path in the URL, for example http://localhost:8080/myproject. The default for the application root will be / (root).

    You can just accept the defaults and click Next.

  5. The Vaadin project step page has various Vaadin-specific application settings. If you are trying Vaadin out for the first time, you should not need to change anything. You can set most of the settings afterwards, except the creation of the portlet configuration.

    Create project template

    Make the wizard create an application class stub.

    Application Name

    The name of the application appears in the browser window title.

    Base package name

    The name of the Java package under which the application class is to be placed.

    Application class name

    Name of the Vaadin application class.

    Create portlet configuration

    When this option is selected, the wizard will create the files needed for running the application in a portal. See Section 11.8, “Portal Integration” for more information on portlets.

    Finally, click Finish to create the project.

  6. Eclipse may ask to switch to J2EE perspective. A Dynamic Web Project uses an external web server and the J2EE perspective provides tools to control the server and manage application deployment. Click Yes.

After the New Project wizard exists, it has done all the work for us: Vaadin libraries are installed in the WebContent/WEB-INF/lib directory, an application class skeleton has been written to src directory, and WebContent/WEB-INF/web.xml already contains a deployment descriptor.


The application class created by the plugin contains the following code:

package com.example.myproject;
import com.vaadin.Application;
import com.vaadin.ui.*;
public class MyprojectApplication extends Application
{
   @Override 
   public void init() {
      Window mainWindow = 
         new Window("Myproject Application");
      Label label = new Label("Hello Vaadin user");
      mainWindow.addComponent(label);
      setMainWindow(mainWindow);
   }
}

Let us add a button to the application to make it a bit more interesting. The resulting init() method could look something like:

public void init() {
   final Window mainWindow = 
      new Window("Myproject Application");
   Label label = new Label("Hello Vaadin user");
   mainWindow.addComponent(label);
   mainWindow.addComponent(
      new Button("What is the time?",
         new Button.ClickListener() {
         public void buttonClick(ClickEvent event) {
            mainWindow.showNotification(
               "The time is " + new Date());
         }
      }));
   setMainWindow(mainWindow);
}

The deployment descriptor WebContent/WEB-INF/web.xml defines Vaadin framework servlet, the application class, and servlet mapping:


For a more detailed treatment of the web.xml file, see Section 4.8.3, “Deployment Descriptor web.xml.

Table of Contents

Preface
1. Introduction
1.1. Overview
1.2. Example Application Walkthrough
1.3. Support for the Eclipse IDE
1.4. Goals and Philosophy
1.5. Background
2. Getting Started with Vaadin
2.1. Installing Vaadin
2.2. Setting up the Development Environment
2.3. QuickStart with Eclipse
2.4. Your First Project with Vaadin
3. Architecture
3.1. Overview
3.2. Technological Background
3.3. Applications as Java Servlet Sessions
3.4. Client-Side Engine
3.5. Events and Listeners
4. Writing a Web Application
4.1. Overview
4.2. Managing the Main Window
4.3. Child Windows
4.4. Handling Events with Listeners
4.5. Referencing Resources
4.6. Shutting Down an Application
4.7. Handling Errors
4.8. Setting Up the Application Environment
5. User Interface Components
5.1. Overview
5.2. Interfaces and Abstractions
5.3. Common Component Features
5.4. Label
5.5. Link
5.6. TextField
5.7. RichTextArea
5.8. Date and Time Input
5.9. Button
5.10. CheckBox
5.11. Selecting Items
5.12. Table
5.13. Tree
5.14. MenuBar
5.15. Embedded
5.16. Upload
5.17. Form
5.18. ProgressIndicator
5.19. Slider
5.20. Component Composition with CustomComponent
6. Managing Layout
6.1. Overview
6.2. Window and Panel Root Layout
6.3. VerticalLayout and HorizontalLayout
6.4. GridLayout
6.5. FormLayout
6.6. Panel
6.7. SplitPanel
6.8. TabSheet
6.9. Accordion
6.10. Layout Formatting
6.11. Custom Layouts
7. Visual User Interface Design with Eclipse (experimental)
7.1. Overview
7.2. Creating a New CustomComponent
7.3. Using The Visual Editor
7.4. Structure of a Visually Editable Component
8. Themes
8.1. Overview
8.2. Introduction to Cascading Style Sheets
8.3. Creating and Using Themes
8.4. Creating a Theme in Eclipse
9. Binding Components to Data
9.1. Overview
9.2. Properties
9.3. Holding properties in Items
9.4. Collecting items in Containers
10. Developing Custom Components
10.1. Overview
10.2. Doing It the Simple Way in Eclipse
10.3. Google Web Toolkit Widgets
10.4. Integrating a GWT Widget
10.5. Defining a Widget Set
10.6. Server-Side Components
10.7. Using a Custom Component
10.8. GWT Widget Development
11. Advanced Web Application Topics
11.1. Special Characteristics of AJAX Applications
11.2. Application-Level Windows
11.3. Embedding Applications in Web Pages
11.4. Debug and Production Mode
11.5. Resources
11.6. Shortcut Keys
11.7. Printing
11.8. Portal Integration
11.9. Google App Engine Integration
11.10. Common Security Issues
11.11. URI Fragment and History Management with UriFragmentUtility
11.12. Capturing HTTP Requests
A. User Interface Definition Language (UIDL)
A.1. API for Painting Components
A.2. JSON Rendering
B. Songs of Vaadin
Index