You are previewing Learning Vaadin 7 - Second Edition.
O'Reilly logo
Learning Vaadin 7 - Second Edition

Book Description

As one of the best web frameworks based on Java, Vaadin is well worth getting familiar with. This tutorial helps you build stunning dynamic web applications that will add new sophistication to your Java capabilities.

  • Construct top-notch web applications with one of the best frameworks based on Java

  • Learn about components, events, layouts, containers, and bindings

  • Create outstanding new components by yourself

  • In Detail

    Vaadin is a new Java web framework for making applications look great and perform well, making your users happy. Vaadin promises to make your user interfaces attractive and usable while easing your development efforts and boosting your productivity as a developer. Vaadin is a web framework that addresses common issues such as poor choice of controls, heterogeneity of technology stacks, page-flow paradigm, and browser compatibility.

    This book a practical guide that will help you in creating top-notch web applications with one of the best frameworks based on Java. You will learn about the fundamental concepts that are the cornerstones of the framework. Also, this book will show you how to integrate Vaadin with popular frameworks and how to run it on top of internal as well as externalized infrastructures.

    Learning Vaadin: Second Edition is a practical, step-by-step tutorial to understanding, using, and mastering the art of RIA development with Vaadin. You will learn about the fundamental concepts that are the cornerstones of the framework, at the same time as making progress on building your own web application. The book will also show you how to integrate Vaadin with other popular frameworks and how to run it on top of internal as well as externalized infrastructures.

    This book will show you how to become a professional Vaadin developer by giving you a concrete foundation through diagrams, practical examples, and ready-to-use source code. It will enable you to grasp all the notions behind Vaadin one step at a time: components, layouts, events, containers, and bindings. You will learn to build first-class web applications using best-of-breed technologies. You will find detailed information on how to integrate Vaadin's presentation layer on top of other widespread technologies, such as Spring, CDI, and Hibernate. Finally, the book will show you how to deploy on different infrastructures like JBoss Portal and Cloud Foundry.

    With this book in hand you will be able to utilize the full range of development and deployment features offered by Vaadin while thoroughly understanding the concepts.

    Table of Contents

    1. Learning Vaadin 7 - Second Edition
      1. Table of Contents
      2. Learning Vaadin 7 - Second Edition
      3. Credits
      4. Foreword
      5. About the Author
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. Vaadin and its Context
        1. Rich applications
          1. Application tiers
            1. Tier migration
              1. Mainframes
              2. Client server
              3. Thin clients
          2. Limitations of the thin-client applications approach
            1. Poor choice of controls
            2. Many unrelated technologies
            3. Browser compatibility
            4. Page flow paradigm
          3. Beyond the limits
            1. What are rich clients?
            2. Some rich client approaches
              1. Ajax
              2. Richness through a plugin
              3. Deploying and updating fat-client from the web
                1. Java Web Start
                2. Update sites
              4. Google Web Toolkit
        2. Why Vaadin?
          1. State of the market
          2. Importance of Vaadin
          3. Vaadin integration
            1. Integrated frameworks
            2. Integration platforms
          4. Using Vaadin in the real world
            1. Concerns about using a new technology
        3. Summary
      10. 2. Environment Setup
        1. Vaadin in Eclipse
          1. Setting up Eclipse
            1. When Eclipse is not installed
            2. Installing the Vaadin plugin
            3. Creating a server runtime
            4. Creating our first Eclipse Vaadin project
              1. Servlet mapping
            5. Testing our application
          2. When Eclipse is already installed
            1. Checking if WTP is present
            2. Adding WTP to Eclipse
        2. Vaadin in IntelliJ IDEA
          1. Setting up IntelliJ
          2. Adding the Vaadin 7 plugin
          3. Creating our first IntelliJ IDEA Vaadin project
            1. Adjusting the result
            2. Adding framework support
            3. Deploying the application automatically
          4. Testing the application
          5. Final touches
            1. Changing the Vaadin version
            2. Context-root
            3. Servlet mapping
        3. Vaadin and other IDEs
          1. Adding Vaadin libraries
          2. Creating the application
          3. Adding the servlet mapping
            1. Declaring the servlet class
            2. Declaring Vaadin's entry point
            3. Declaring the servlet mapping
        4. Summary
      11. 3. Hello Vaadin!
        1. Understanding Vaadin
          1. Vaadin's philosophy
          2. Vaadin's architecture
            1. Client-server communication
              1. HTTP protocol
              2. JSON message format
            2. The client part
            3. The server part
            4. Client-server synchronization
        2. Deploying a Vaadin application
          1. Inside the IDE
            1. Creating an IDE-managed server
              1. Selecting the tab
              2. Creating a server
              3. Verifying the installation
            2. Adding the application
            3. Launching the server
          2. Outside the IDE
            1. Creating the WAR
            2. Launching the server
        3. Using Vaadin applications
          1. Browsing Vaadin
          2. Out-of-the-box helpers
            1. The debug mode
            2. Restart the application, not the server
        4. Behind the surface
          1. Stream redirection to a Vaadin servlet
          2. Vaadin request handling
          3. What does a UI do?
            1. UI features
            2. UI configuration
            3. UI and session
          4. Scratching the surface
            1. The source code
            2. The generated code
            3. Things of interest
        5. Summary
      12. 4. Components and Layouts
        1. Thinking in components
          1. Terminology
          2. Component class design
            1. Component
            2. MethodEventSource
            3. Abstract client connector
            4. Abstract component
              1. Immediate mode
          3. UIs
            1. HasComponents
            2. Single component container
            3. UI
              1. Theming
            4. Panel
          4. Windows
            1. Window structure
            2. Customizing windows
              1. Basic configuration
              2. Location
              3. Modality
          5. Labels
            1. Label class hierarchy
            2. Property
            3. Label
              1. Formats
          6. Text inputs
            1. Conversion
            2. Validation
              1. Validator
                1. Validators hierarchy
                2. Error message
              2. Validatable
            3. Change buffer
              1. Buffered and validatable
            4. Input
              1. Focusable
              2. Field
              3. The text field
                1. Null
                2. Input prompt
                3. Cursor
                4. Selection
                5. A "real-world" text field example
          7. More Vaadin goodness
            1. Page
              1. Title
              2. Navigation
              3. URL fragment
            2. Third-party content
              1. Resources
              2. Browser window opener
            3. User messages
              1. The notification class
              2. Notifications additional properties
              3. Displaying notifications
        2. Laying out the components
          1. Size
          2. Layouts
            1. About layouts
            2. Component container
            3. Layout and abstract layout
            4. Layout types
              1. Simple layouts
              2. Advanced layouts
            5. Choosing the right layout
          3. Split panels
        3. Bringing it all together
          1. Introducing Twaattin
            1. The Twaattin design
            2. The login screen
            3. The main screen
          2. Let's code!
            1. Project setup
            2. Project sources
              1. UI
              2. The login screen
              3. The timeline screen
        4. Summary
      13. 5. Event Listener Model
        1. Event-driven model
          1. The observer pattern
            1. Enhancements to the pattern
              1. Event
              2. Event details
              3. Event types
          2. Events in Java EE
            1. UI events
              1. Client-server events
              2. Client events
              3. Limitations of URL and custom JavaScript for events
        2. Event model in Vaadin
          1. Standard event implementation
            1. Event class hierarchy
              1. Event
              2. Typed events
            2. Listener interfaces
              1. Window
            3. Managing listeners
            4. Method event source details
            5. Abstract component and event router
          2. Expanding our view
            1. Button
          3. Events outside UI
            1. User change event
          4. Architectural considerations
            1. Anonymous inner classes as listeners
            2. Components as listeners
            3. Presenters as listeners
            4. Services as listeners
            5. Conclusion on architecture
          5. Twaattin is back
            1. Project sources
              1. The UI
              2. The login screen
              3. The login behavior
            2. Additional features
              1. The timeline window
              2. The logout behavior
        3. Summary
      14. 6. Containers and Related Components
        1. Data binding
          1. Data binding properties
            1. Renderer and editor
            2. Buffering
            3. Data binding
        2. Data in Vaadin
          1. Entity abstraction
            1. Property
              1. AbstractProperty
              2. ObjectProperty
              3. Property formatter
              4. Handling changes
            2. Item
              1. Method property
              2. The right level of abstraction
              3. Field group
                1. Configuring field types
                2. Changing captions
                3. Group commit/discard
            3. Container
              1. Filtering and sorting
                1. Filterable
                2. Filter
                3. Ordered
                4. Item sorter
                5. Concrete indexed containers
              2. Hierarchical
          2. Containers and the GUI
            1. Container datasource
              1. Displaying items
              2. Handling new items
              3. Null items
            2. Container components
            3. Tables
              1. Table structure
              2. Columns
                1. Width
                2. Collapsing
                3. Header and footer
                4. Row header column
                5. Ordering and reordering
                6. Formatting properties and generated columns
              3. Sorting
                1. User sorting
                2. Programmatic sorting
              4. Viewpoint
                1. Viewpoint change event
                2. Improving responsiveness
              5. Editing
              6. Selection
              7. Drag-and-drop
                1. Transferable
                2. Drag source
                3. Drop target
                4. Accept criterion
                5. Table drag-and-drop
            4. Trees
              1. Collapse and expand
              2. Parent and child
              3. Item labels
        3. Refining Twaattin
          1. Prerequisites
          2. Adaptations
          3. Sources
            1. The login screen
            2. The login behavior
            3. The timeline screen
            4. The tweets refresh behavior
            5. Column generators
        4. Summary
      15. 7. Core Advanced Features
        1. Accessing the JavaEE API
          1. Servlet request
          2. Servlet response
          3. Wrapped session
        2. Navigation API
          1. URL fragment
          2. Views
          3. Navigator
            1. Initial view
            2. Error view
            3. Dynamic view providers
          4. Event model around the Navigation API
          5. Final word on the Navigator API
        3. Embedding Vaadin
          1. Basic embedding
          2. Nominal embedding
            1. Page headers
            2. The div proper
            3. The bootstrap script
            4. UI initialization call
        4. Real-world error handling
          1. The error messages
          2. Component error handling
          3. General error handling
        5. SQL container
          1. Architecture
          2. Features
          3. Queries and connections
          4. Database compatibility
          5. Joins
            1. References
            2. Free form queries
          6. Related add-ons
        6. Server push
          1. Push innards
          2. Installation
          3. How-to
          4. Example
        7. Twaattin improves!
          1. Ivy dependencies
          2. Twaattin UI
          3. Tweet refresher behavior
          4. Twitter service
        8. Summary
      16. 8. Featured Add-ons
        1. Vaadin add-ons directory
          1. Add-ons search
          2. Typology
          3. Stability
          4. Add-ons presentation
            1. Summarized view
            2. Detailed view
        2. Noteworthy add-ons
          1. Button group
            1. Prerequisites
            2. Core concepts
              1. GWT modules
              2. Widget sets
            3. How-to
            4. Conclusion
          2. Clara
            1. Prerequisites
            2. How-to
              1. XML
              2. Inflating
              3. Adding behavior
              4. Data sources
              5. Creating complex components
            3. Limitations
            4. Conclusion
          3. JPA Container
            1. Concepts
            2. Prerequisites
              1. Dependency
              2. Model
              3. Application server
                1. Download, install, and integrate
                2. Create the data source
            3. How-to
            4. Conclusion
          4. CDI Utils
            1. Core concepts
              1. Inversion of Control and Dependency Injection
              2. DI use cases
            2. Prerequisites
            3. How-to
              1. CDI injection
              2. Event observers
              3. Components declaration
            4. Conclusion
        3. Summary
      17. 9. Creating and Extending Components and Widgets
        1. Component composition
          1. Manual composition
          2. Designing custom components
          3. Graphic composition
            1. Visual editor setup
            2. Visual Designer use
              1. Position and size
            3. Limitations
              1. Restricted compatibility
              2. Top-level element
              3. Rigid structure
        2. Client-side extensions
          1. Connector architecture
          2. How-to
        3. Shared state
          1. How-to
        4. Server RPC
          1. Server RPC architecture
          2. How-to
        5. GWT widget wrapping
          1. Vaadin GWT architecture
          2. How-to server-side
          3. How-to client-side
            1. Widget styling
          4. Example
            1. Prerequisites
            2. Server component
            3. Client classes
        6. JavaScript wrapping
          1. How-to
          2. Example
            1. Prerequisites
            2. Core
        7. Componentized Twaattin
          1. Designing the component
          2. Updating Twaattin's code
            1. Data Transfer Object
            2. Status component
            3. Status converter
            4. Timeline screen
        8. Summary
      18. 10. Enterprise Integration
        1. Build tools
          1. Available tools
            1. Apache Ant
            2. Apache Maven
            3. Fragmentation
            4. Final choice
          2. Tooling
          3. Maven in Vaadin projects
            1. Mavenize Vaadin projects
            2. Vaadin support for Maven projects
              1. Widget compilation
              2. Running Twaattin outside IDE
          4. Mavenizing Twaattin
            1. Preparing the migration
            2. Enabling dependency management
            3. Finishing touches
              1. Cleaning up warning messages
              2. Optimizations
            4. Final POM
        2. Portals
          1. Portal, container, and portlet
          2. Choosing a platform
            1. Liferay
            2. GateIn
              1. Downloading and installation
              2. Launch
          3. Tooling
          4. A simple portlet
            1. Creating a project
            2. Portlet project differences
              1. Portlet deployment descriptor
              2. Portal proprietary files
              3. Similarities
            3. Using the portlet in GateIn
              1. Deploying in GateIn
              2. Adding the portlet to a page
                1. Sign in
                2. Refresh portlets
                3. Add portlet
          5. Configuring GateIn for Vaadin
            1. Themes and widgetsets
              1. Serve files from the portal
              2. Serve files from an HTTP server
          6. Advanced integration
            1. Restart and debug
            2. Handling portlet specifics
          7. Portlet development strategies
            1. Keep our portlet servlet-compatible
            2. Portal debug mode
            3. Updating a deployed portlet
        3. OSGi
          1. Choosing a platform
            1. Glassfish
              1. Deploying bundles
                1. Prerequisites
                2. Telnet deployment
                3. File system deployment
                4. Web console deployment
          2. Tooling
          3. Vaadin OSGi use cases
            1. Vaadin bundling
            2. Modularization
          4. Hello OSGi
            1. Making a bundle
            2. Export, deploy, and run
            3. Correcting errors
              1. Vaadin servlet
              2. Vaadin bootstrap
          5. Integrating Twaattin
            1. Bundle plugin
            2. Multiplatform build
        4. Cloud
          1. Cloud offering levels
          2. State of the market
          3. Hello cloud
            1. Registration
            2. Cloud setup
              1. Resources
              2. Balancing
              3. Application server and JDK
              4. Database and cache
              5. Miscellaneous
            3. Application deployment
        5. Summary
      19. Index