Book of Vaadin 4Th Edition Book of Vaadin: 4Th Edition Vaadin Ltd Marko Grönroos 4Th Edition 1St Revision Edition Vaadin Framework 6.7.0
Total Page:16
File Type:pdf, Size:1020Kb
Book of Vaadin 4th Edition Book of Vaadin: 4th Edition Vaadin Ltd Marko Grönroos 4th Edition 1st Revision Edition Vaadin Framework 6.7.0 Published: 2012-04-18 Copyright © 2000-2012 Vaadin 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. This work is licensed under the Creative Commons CC-BY-ND License Version 2.0 [http://creativecommons.org/licenses/by-nd/2.0/legalcode]. Table of Contents Preface .......................................................................................................................... xiii I. Vaadin Core Framework .................................................................................................. 1 1. Introduction ......................................................................................................... 3 1.1. Overview .................................................................................................... 3 1.2. Example Application Walkthrough ................................................................ 5 1.3. Support for the Eclipse IDE ......................................................................... 6 1.4. Goals and Philosophy ................................................................................. 6 1.5. Background ................................................................................................ 7 2. Getting Started with Vaadin ................................................................................. 9 2.1. Setting up the Development Environment ..................................................... 9 2.1.1. Installing Java SDK ........................................................................ 10 2.1.2. Installing Eclipse IDE ...................................................................... 11 2.1.3. Installing Apache Tomcat ................................................................ 12 2.1.4. Firefox and Firebug ........................................................................ 12 2.2. Installing Vaadin ........................................................................................ 13 2.2.1. Vaadin Plugin for Eclipse ................................................................ 13 2.2.2. Installing the JAR Package ............................................................. 16 2.3. Your First Project with Vaadin ..................................................................... 16 2.3.1. Creating the Project ....................................................................... 16 2.3.2. Exploring the Project ...................................................................... 21 2.3.3. Setting Up and Starting the Web Server .......................................... 22 2.3.4. Running and Debugging ................................................................. 24 2.4. Creating a Project with NetBeans ............................................................... 25 2.4.1. Regular Web Application Project ..................................................... 25 2.4.2. Maven Project from Vaadin Archetype ............................................. 26 2.5. Creating a Project with Maven ................................................................... 27 3. Architecture ....................................................................................................... 31 3.1. Overview .................................................................................................. 31 3.2. Technological Background ......................................................................... 34 3.2.1. AJAX ............................................................................................. 34 3.2.2. Google Web Toolkit ........................................................................ 34 3.2.3. JSON ............................................................................................ 35 3.3. Applications as Java Servlet Sessions ........................................................ 35 3.4. Client-Side Engine .................................................................................... 35 3.5. Events and Listeners ................................................................................. 37 4. Writing a Web Application .................................................................................. 39 4.1. Overview .................................................................................................. 39 4.2. Managing the Main Window ....................................................................... 42 4.3. Sub-Windows ........................................................................................... 43 4.3.1. Opening and Closing a Sub-Window ............................................... 43 4.3.2. Window Positioning ........................................................................ 45 4.3.3. Scrolling Sub-Window Content ........................................................ 45 4.3.4. Modal Windows .............................................................................. 46 4.4. Handling Events with Listeners .................................................................. 46 4.5. Referencing Resources ............................................................................. 49 4.5.1. Resource Interfaces and Classes .................................................... 49 4.5.2. File Resources ............................................................................... 50 4.5.3. Class Loader Resources ................................................................ 50 4.5.4. Theme Resources .......................................................................... 50 Book of Vaadin iii Book of Vaadin 4.5.5. Stream Resources ......................................................................... 50 4.6. Shutting Down an Application .................................................................... 52 4.6.1. Closing an Application .................................................................... 52 4.6.2. Handling the Closing of a Window ................................................... 53 4.7. Handling Errors ......................................................................................... 53 4.7.1. Error Indicator and message ........................................................... 53 4.7.2. Notifications ................................................................................... 54 4.7.3. Customizing System Messages ...................................................... 56 4.7.4. Handling Uncaught Exceptions ...................................................... 57 4.8. Setting Up the Application Environment ...................................................... 58 4.8.1. Creating Deployable WAR in Eclipse ............................................... 59 4.8.2. Web Application Contents ............................................................... 59 4.8.3. Deployment Descriptor web.xml .................................................... 59 5. User Interface Components ............................................................................... 63 5.1. Overview .................................................................................................. 64 5.2. Interfaces and Abstractions ....................................................................... 65 5.2.1. Component Interface ..................................................................... 66 5.2.2. AbstractComponent ..................................................................... 67 5.2.3. Field Components (Field and AbstractField) .................................. 67 5.3. Common Component Features .................................................................. 70 5.3.1. Caption ......................................................................................... 70 5.3.2. Description and Tooltips .................................................................. 71 5.3.3. Enabled ......................................................................................... 72 5.3.4. Icon ............................................................................................... 73 5.3.5. Locale ........................................................................................... 73 5.3.6. Read-Only ..................................................................................... 76 5.3.7. Style Name .................................................................................... 77 5.3.8. Visible ........................................................................................... 77 5.3.9. Sizing Components ........................................................................ 78 5.3.10. Managing Input Focus .................................................................. 80 5.4. Label ....................................................................................................... 80 5.4.1. Content Mode ................................................................................ 81 5.4.2. Making Use of the XHTML Mode ..................................................... 83 5.4.3. Spacing with a Label .....................................................................