Book of Vaadin Vaadin 6 Book of Vaadin: Vaadin 6 Oy IT Mill Ltd Marko Grönroos Vaadin 6.1.0
Total Page:16
File Type:pdf, Size:1020Kb
Book of Vaadin Vaadin 6 Book of Vaadin: Vaadin 6 Oy IT Mill Ltd Marko Grönroos Vaadin 6.1.0 Published: 2009-09-09 Copyright © 2000-2009 Oy IT Mill Ltd. Abstract Vaadin is a server-side AJAX web application development framework that enables developers to build high-quality user interfaces with Java. It provides a library of ready-to-use user interface components and a clean framework for creating your own components. The focus is on ease-of-use, re-usability, extensibility, and meeting the requirements of large enterprise applications. Vaadin has been used in production since 2001 and it has proven to be suitable for building demanding business applications. All rights reserved. Table of Contents Preface ............................................................................................................................ ix 1. Introduction ................................................................................................................. 1 1.1. Overview ............................................................................................................ 1 1.2. Example Application Walkthrough ........................................................................ 3 1.3. Support for the Eclipse IDE ................................................................................. 4 1.4. Goals and Philosophy ......................................................................................... 4 1.5. Background ........................................................................................................ 5 2. Getting Started with Vaadin ......................................................................................... 9 2.1. Installing Vaadin ................................................................................................. 9 2.1.1. Installing the Distribution Package ........................................................... 10 2.1.2. Starting the Content Browser .................................................................. 10 2.1.3. Package Contents .................................................................................. 11 2.1.4. Demo Applications ................................................................................. 13 2.2. Setting up the Development Environment ........................................................... 13 2.2.1. Installing Java SDK ................................................................................ 14 2.2.2. Installing Eclipse IDE .............................................................................. 15 2.2.3. Installing Apache Tomcat ........................................................................ 16 2.2.4. Firefox and Firebug ................................................................................ 16 2.2.5. Vaadin Plugin for Eclipse ........................................................................ 17 2.3. QuickStart with Eclipse ...................................................................................... 20 2.3.1. Starting Eclipse ...................................................................................... 20 2.3.2. Importing Vaadin as a Project ................................................................. 20 2.3.3. Running the Demo Applications in Eclipse ............................................... 21 2.3.4. Debugging the Demo Applications in Eclipse ........................................... 24 2.3.5. Using QuickStart as a Project Skeleton ................................................... 25 2.4. Your First Project with Vaadin ............................................................................. 25 2.4.1. Creating the Project ............................................................................... 25 2.4.2. Exploring the Project .............................................................................. 29 2.4.3. Setting Up and Starting the Web Server .................................................. 31 2.4.4. Running and Debugging ......................................................................... 33 3. Architecture ............................................................................................................... 35 3.1. Overview .......................................................................................................... 35 3.2. Technological Background ................................................................................. 38 3.2.1. AJAX ..................................................................................................... 38 3.2.2. Google Web Toolkit ................................................................................ 38 3.2.3. JSON .................................................................................................... 39 3.3. Applications as Java Servlet Sessions ................................................................ 39 3.4. Client-Side Engine ............................................................................................ 39 3.5. Events and Listeners ......................................................................................... 40 4. Writing a Web Application .......................................................................................... 43 4.1. Overview .......................................................................................................... 43 4.2. Managing the Main Window ............................................................................... 46 4.3. Child Windows .................................................................................................. 46 4.3.1. Opening and Closing a Child Window ...................................................... 47 4.3.2. Window Positioning ................................................................................ 49 4.3.3. Modal Windows ...................................................................................... 49 4.4. Handling Events with Listeners .......................................................................... 50 4.5. Referencing Resources ..................................................................................... 52 4.5.1. Resource Interfaces and Classes ............................................................ 53 Book of Vaadin iii Book of Vaadin 4.5.2. File Resources ....................................................................................... 54 4.5.3. Class Loader Resources ........................................................................ 54 4.5.4. Theme Resources .................................................................................. 54 4.5.5. Stream Resources ................................................................................. 54 4.6. Shutting Down an Application ............................................................................ 56 4.6.1. Closing an Application ............................................................................ 56 4.6.2. Handling the Closing of a Window ........................................................... 56 4.7. Handling Errors ................................................................................................. 57 4.7.1. Error Indicator and message ................................................................... 57 4.7.2. Notifications ........................................................................................... 58 4.7.3. Handling Uncaught Exceptions .............................................................. 60 4.8. Setting Up the Application Environment .............................................................. 61 4.8.1. Creating Deployable WAR in Eclipse ....................................................... 61 4.8.2. Web Application Contents ....................................................................... 62 4.8.3. Deployment Descriptor web.xml ............................................................ 62 5. User Interface Components ....................................................................................... 65 5.1. Overview .......................................................................................................... 66 5.2. Interfaces and Abstractions ............................................................................... 67 5.2.1. Component Interface ............................................................................. 68 5.2.2. AbstractComponent ............................................................................. 69 5.2.3. Field Components (Field and AbstractField) .......................................... 70 5.3. Common Component Features .......................................................................... 72 5.3.1. Description and Tooltips .......................................................................... 72 5.3.2. Sizing Components ................................................................................ 73 5.3.3. Managing Input Focus ............................................................................ 74 5.4. Label ............................................................................................................... 75 5.5. Link ................................................................................................................. 78 5.6. TextField ......................................................................................................... 78 5.7. RichTextArea .................................................................................................. 79 5.8. Date and Time Input .........................................................................................