Data-Centric Applications with Vaadin 8 - Alejandro Duarte - E-Book

Data-Centric Applications with Vaadin 8 E-Book

Alejandro Duarte

0,0
27,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

This book teaches you everything you need to know to create stunning Vaadin applications for all your web development needs. Deep dive into advanced Vaadin concepts while creating your very own sample Vaadin application.

Key Features

  • A one-stop book to enhance your working knowledge with Vaadin.
  • Explore and implement the architecture of Vaadin applications.
  • Delve into advanced topics such as data binding, authentication and authorization to improvise your application’s performance.

Book Description

Vaadin is an open-source Java framework used to build modern user interfaces. Vaadin 8 simplifies application development and improves user experience. The book begins with an overview of the architecture of Vaadin applications and the way you can organize your code in modules.Then it moves to the more advanced topics about advanced topics such as internationalization, authentication, authorization, and database connectivity. The book also teaches you how to implement CRUD views, how to generate printable reports, and how to manage data with lazy loading.

By the end of this book you will be able to architect, implement, and deploy stunning Vaadin applications, and have the knowledge to master web development with Vaadin.

What you will learn

  • Modularize your Vaadin applications with Maven
  • Create high quality custom components
  • Implement robust and secure authentication and authorization mechanisms
  • Connect to SQL databases efficiently
  • Design robust CRUD (Create, Read, Update, Delete) views
  • Generate stunning reports
  • Improve resource consumption by using lazy loading

Who this book is for

If you area Software developer with previous experience with Vaadin and would like to gain more comprehensive and advanced skills in Vaadin web development, then this book is for you.

Alejandro Duarte is a developer advocate and trainer at Vaadin Ltd. He is also the author of Vaadin 7 UI Design by Example: Beginner's Guide (Packt, 2013). Graduating from the National University of Colombia with a B.S. in computer science, Alejandro learned how to program with the BASIC programming language at age 13 and has worked on many software development projects in startup-like and big companies in several countries. When he isn't coding, he splits his time between his family, his beautiful girlfriend, and his passion for the electric guitar. You can follow him on Twitter at @alejandro_du.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 210

Veröffentlichungsjahr: 2018

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Data-Centric Applications with Vaadin 8

 

 

 

 

 

 

 

 

Develop and maintain high-quality web applications using Vaadin

 

 

 

 

 

 

 

 

 

Alejandro Duarte

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Data-Centric Applications with Vaadin 8

Copyright © 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Acquisition Editor:Noyonika DasContent Development Editor:Mohammed Yusuf ImaratwaleTechnical Editor: Shweta JadhavCopy Editor: Safis EditingProject Coordinator:Hardik BhindeProofreader: Safis EditingIndexer:Mariammal ChettiyarGraphics:Jason MonteiroProduction Coordinator:Shantanu Zagade

First published: April 2018

Production reference: 1260418

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78328-884-7

www.packtpub.com

To my mother. Simply, thank you, for everything.
– Alejandro Duarte
mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

PacktPub.com

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

Foreword

When introducing Vaadin to a Java developer for the first time, I have often described it as the frontend framework for the backend developer. While this is an oversimplification, most people with little experience on the frontend tend to learn Vaadin quickly and are able to build beautiful web applications with it. I believe this is due to two distinctive properties of Vaadin: one can write the whole web application in server-side Java, and the user interface components look good and feature-rich by default. If you feel at home writing server-side Java and working with databases, but get frustrated when building the user interface in JavaScript and HTML, this book is for you. Although you need to know the fundamentals of Vaadin, the book starts with the basic concepts and introduces everything you need to become productive at building a data-centric web applications. The approach in the book is practical, showing you by example how to solve the most common challenges and getting you ready for learning more as you go. Alejandro Duarte would be a great guide for introducing any technology, and we are very fortunate that he joined the Vaadin team after publishing his first book on Vaadin. I hope this book inspires you to build amazing web apps in no time. For questions not discussed in this book, I invite you to join the friendly Vaadin community and share your experiences with other developers who are eager to guide you further.

 

 

 

Joonas Lehtinen

Founder and CEO of Vaadin

Contributors

About the author

Alejandro Duarte is a developer advocate and trainer at Vaadin Ltd. He is also the author of Vaadin 7 UI Design by Example: Beginner's Guide (Packt, 2013). Graduating from the National University of Colombia with a B.S. in computer science, Alejandro learned how to program with the BASIC programming language at age 13 and has worked on many software development projects in startup-like and big companies in several countries. When he isn't coding, he splits his time between his family, his beautiful girlfriend, and his passion for the electric guitar. You can follow him on Twitter at @alejandro_du.

I'd like to thank the teams at Packt Publishing and Vaadin. Special thanks to Joonas Lehtinen, Sami Ekblad, Matti Tahvonen, and Marcus Hellberg, who in one way or another influenced this book. Thanks to my friends in Finland and Colombia for their motivation. Last but not least, thanks to my parents and siblings for being so supportive; I genuinely enjoyed writing part of this book with your company.

About the reviewer

David Hofmann is a self-taught developer who started working right after high school. 14 years down the lane, he can't help but keep enjoying it. Negotiating and management are the new challenges he finds somewhat more complex than coding, yet much more powerful when delivering solutions. Playing guitar as a hobby keeps him calm, and coffee manages to do the opposite.

 

 

 

 

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Data-Centric Applications with Vaadin 8

Dedication

Packt Upsell

Why subscribe?

PacktPub.com

Foreword

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Code in Action

Conventions used

Get in touch

Reviews

Creating New Vaadin Projects

Technical requirements

About the demo applications

Understanding the source code

Understanding the architecture of a Vaadin application

Creating a new project from scratch

Maven dependencies

Servlets and UIs

Maven plugins

Components and layouts

Listeners and binders

Events and listeners

Data binding

Resources and themes

Widget sets and add-ons

Summary

Modularization and Main Screens

Technical requirements

Creating a multi-module Maven project

Implementing an application's main screen

Defining an API for an application's main screen

Implementing support classes

Implementing a concrete application's main screen

Adding and configuring the required UI components

Implementing the ApplicationLayout interface

Implementing the menu

Modularizing Vaadin applications

Identifying alternatives for modularization

Registering modules with the application

Discovering modules

Implementing new modules

Summary

Implementing Server-Side Components with Internationalization

Technical requirements

Using extensions to develop a UI component

Extending VerticalLayout

Why avoid extension?

Using composition to develop custom components

Implementing a factory

Using the Composite class

Using the LoginForm class

Using internationalization for Multiple Language Support

Removing hardcoded strings

Getting localized strings

Getting and setting the locale

Summary

Implementing Authentication and Authorization

Technical requirements

Implementing public and private views

Using the HTTP session and cookies to identify users

Keeping track of authenticated users

Implementing the login/logout process

Implementing the remember me feature

Enabling features according to a user's roles

Coding authorization logic in UI components

Coding authorization using request data

Getting request information

Routing requests to a UI component

Coding authorization with the help of a Navigator

Summary

Connecting to SQL Databases Using JDBC

Technical requirements

Introduction to JDBC

Adding a JDBC driver for your database

Establishing a database connection through a connection pool

Creating a statement and executing an SQL query

Getting and processing a result set

Closing a database connection

Implementing data repositories

Defining a domain model

Implementing repositories and services

The active record pattern

Summary

Connecting to SQL Databases Using ORM Frameworks

Technical requirements

Using object-relational mapping frameworks

Connecting to SQL databases using JPA

Defining a persistence unit

Creating an EntityManagerFactory

Implementing Entity classes

Executing queries

Implementing a Vaadin UI to list and save Entities

Connecting to SQL databases using MyBatis

Defining a database connection

Implementing mapper classes

Implementing a service class

Connecting to SQL databases using jOOQ

Defining a database connection

Reverse-engineering the database schema

Running queries

Summary

Implementing CRUD User Interfaces

Technical requirements

CRUD user interface design

In-place fields

Modal pop-up windows

Hierarchical menus

The domain model

Implementing a CRUD using an editable Grid component

Implementing the read operation

Implementing the update operation

Adding Bean Validation with JSR-303

Implementing a CRUD using Grids and forms

Implementing the read operation

Implementing the create and update operations

Implementing the delete operation

Using the Crud UI add-on

Filtering

Summary

Adding Reporting Capabilities

Technical requirements

The example application

The data model

The Vaadin UI

Integrating JasperReports with Vaadin

Getting the data

Designing the report

Rendering a report as HTML

Adding charts

Generating a report in a background task

Exporting a report to a PDF

Server Push

Summary

Lazy Loading

Technical requirements

The example application

The data model

The Vaadin UI

Preparing the backend for lazy loading

Lazy loading with the Grid component

Adding filters

Ordering rows in Grid components

Preparing the backend services

Enabling ordering in the UI

UX and large datasets

Lazy loading Grid versus direct search

Infinite lazy loading

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

Vaadin Framework is an open source Java web framework released under the Apache License. The framework is well documented, includes sophisticated UI components and themes, has been battle-tested in real-life applications, and is supported by a committed company and a vibrant community that contributes to the framework through forum answers and hundreds of add-ons.

Vaadin Framework allows developers to implement web user interfaces using Java code that runs on the server's JVM. The UI is rendered as HTML5 on the browser. The framework provides fully automated communication between the browser and the server through a programming model close to Swing or AWT. This allows developers/programmers bringing the benefits of object-oriented techniques to the presentation layer in web applications.

Data-Centric Applications with Vaadin 8 is a practical guide that teaches you how to implement some of the most typical requirements in web applications where data management is central. You will learn about internationalization, authentication, authorization, database connectivity, CRUD views, report generation, and lazy loading of data.

This book will also help you to exercise your programming and software design skills by showing you how to make good decisions both at the UX and code level. You will learn how to modularize your application and how to provide APIs on top of your UI components to increase reusability and maintainability.

Who this book is for

This book is ideal for developers with a good understanding of the Java programming language and a basic knowledge of Vaadin Framework who want to improve their skills with the framework. If you want to learn concepts, techniques, technologies, and practices to help you master web development with Vaadin and see how common application features are developed in real-life applications, this book is for you.

What this book covers

Chapter 1, Creating New Vaadin Projects, demonstrates how to create a new Vaadin Maven project from scratch and explains the main architecture and parts of a Vaadin application.

Chapter 2, Modularization and Main Screens, explains how to design an API for implementing main screens and shows how to create functional application modules that are registered at runtime.

Chapter 3, Implementing Server-Side Components with Internationalization, discusses implementation strategies for implementing custom UI components with internationalization support.

Chapter 4, Implementing Authentication and Authorization, explores different approaches for implementing secure authentication and authorization mechanisms in Vaadin applications.

Chapter 5, Connecting to SQL Databases Using JDBC, focuses on JDBC, connection pools, and repository classes in order to connect to SQL databases.

Chapter 6, Connecting to SQL Databases Using ORM Frameworks, outlines how to use JPA, MyBatis, and jOOQ to connect to SQL databases from Vaadin applications.

Chapter 7, Implementing CRUD User Interfaces, takes you through user interface design and the implementation of CRUD (create, read, update, and delete) views.

Chapter 8, Adding Reporting Capabilities, shows how to generate and visualize print-preview reports using JasperReports.

Chapter 9, Lazy Loading, looks at how to implement lazy loading to make your applications consume fewer resources when dealing with large datasets.

To get the most out of this book

You'll get the most out of this book if you already have some kind of experience with the Vaadin Framework. If you don't, go through the official online tutorial at https://vaadin.com/docs/v8/framework/tutorial.html before continuing with this book.

In order to use the companion code, you need the Java SE Development Kit and Java EE SDK version 8 or later. You also need Maven version 3 or later. A Java IDE with Maven support, such as IntelliJ IDEA, Eclipse, or NetBeans is recommended.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packtpub.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Data-Centric-Applications-with-Vaadin-8. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/DataCentricApplicationswithVaadin8_ColorImages.pdf.

Code in Action

Visit the following link to check out videos of the code being run:https://goo.gl/qFmc3L

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

Creating New Vaadin Projects

This first chapter serves as the foundations for a journey full of interesting technologies, thrilling challenges, and useful code. If you are reading this book, the chances that you have coded a Vaadin application before are high. You probably have a basic understanding of the key players in a Vaadin application: components, layouts, listeners, binders, resources, themes, and widget sets; and you, of course, have had your share of Java coding!

Having a solid base when starting a project, not only with Vaadin but with any other technology, plays an important role in successful projects. Understanding what your code does and why it is required helps you make better decisions and become more productive. This chapter will help you understand what is really needed to run a Vaadin application and how you can become more confident about the dependencies and Maven configuration required to start a new Vaadin project.

This chapter covers the following topics:

The main Java dependencies in Vaadin

Servlets and UIs

Maven plugins

Key elements in a Vaadin application

Technical requirements

You will be required to have Java SE Development Kit and Java EE SDK version 8 or later. You also need Maven version 3 or later. A Java IDE with Maven support, such as IntelliJ IDEA, Eclipse, or NetBeans is recommended. Finally, to use the Git repository of this book, you need to install Git.

The code files of this chapter can be found on GitHub:https://github.com/PacktPublishing/Data-centric-Applications-with-Vaadin-8/tree/master/chapter-01

Check out the following video to see the code in action:https://goo.gl/RHavBs

About the demo applications

This book offers value in two ways: the book itself with its explanations, and its companion source code. Instead of developing one single application throughout the book, several small demo applications demonstrate the concepts explained in each chapter. This helps you to jump to any chapter you are interested in, and fully understand the purpose of each part of the code without worrying about the technicalities that we have looked at in other chapters.

Understanding the source code

Before you compile the project, you have to start an H2 database instance. For your convenience, a server is configured in theData-centric-Applications-with-Vaadin-8/chapter-05 Maven module. You can create a run configuration for the following Maven command or you can run it directly on the command line:

cd Data-centric-Applications-with-Vaadin-8/chapter-05

mvn test exec:java -Dexec.mainClass="packt.vaadin.datacentric.chapter05.jdbc.H2Server"

Once the database is up and running, you can build all the demo applications by executing the following:

cd Data-centric-Applications-with-Vaadin-8

mvn install

All the demo applications are aggregated in a multi-module Maven project, where each module corresponds to one chapter of the book.

This book assumes that you are proficient enough with Maven to follow the example applications of each chapter. If you have no previous experience with Maven or multi-module Maven projects, please spend some time going through the tutorials and documentation at: http://maven.apache.org/guides.

Each chapter's module may contain multiple sub-modules depending on the concepts being explained in that chapter. We will use the Jetty Maven plugin to run the examples. Most IDEs today have good support for Maven. The best way to use this book's code is by importing theData-centric-Applications-with-Vaadin-8 Maven project into your IDE and creating individual running configurations for each demo application.There are tons of resources online that explain how to do this for the most popular IDEs, such as IntelliJ IDEA, NetBeans, and Eclipse. For example, to run the example application for this chapter in IntelliJ IDEA, create a new running configuration like the following:

Make sure the working directory corresponds to the correct module in the project. Alternatively, you can run the application by executing the following on the command line:

cd Data-centric-Applications-with-Vaadin-8/chapter-01

mvn package jetty:run

This executes the package Maven phase and starts a Jetty server. The application should be available at http://localhost:8080.

So, go ahead! Download the source code, import it into your IDE, and run a couple of examples. Feel free to explore the code, modify it, and even use it in your own projects.

Understanding the architecture of a Vaadin application

What's the best way of starting a new Vaadin project? It’s hard to say. It depends on your previous experience, current development environment setup, and your own preferences. One of the most popular ways of creating a new Vaadin project is by using one of the official Maven archetypes. You have probably used the vaadin-archetype-application Maven archetype, which is good to quickly get started with Vaadin. Maybe you have used the vaadin-archetype-widgetset archetype to create a Vaadin add-on, or maybe you have used the vaadin-archetype-application-multimoduleorvaadin-archetype-application-example archetypes to bootstrap some of your applications. IDEs such as Eclipse provide tools to create a Vaadin project without even thinking about Maven archetypes.

All of those archetypes and tools are good in the sense that they get you started quickly and show some good practices. However, when you create a project from scratch, you get a better understanding of the whole architecture of the application. Of course, you can use the archetypes if you already feel comfortable enough with every part of the generatedpom.xml file. However, building the project from scratch is a good way of truly understanding and controlling the configuration of your Vaadin application.

Creating a new project from scratch

Usually, you would use the vaadin-archetype-application or vaadin-archetype-application-multimodule Maven archetypes to create a new Vaadin application. There's nothing wrong with using these if the generated code suits your needs. However, these archetypes generate more code than you need, partially because they try to show you how to get started with Vaadin and partially because they are general-purpose starters which are well-suited for most projects. But let's gain full control (and understanding) of the web application by creating a Vaadin project in a very different way—a more fine-grained, controlled way.

A Vaadin application is, at the end of the day, a Java application packaged as a WAR file. You can think of it as a standard web application in which you drop some JARs that allow you to build a web UI using the Java Programming Language instead of HTML and JavaScript. Is it as simple as dropping some JARs into your Java project? Let's find out!

Use the maven-archetype-webapp to generate a simple Java web application by executing the following on the command line:

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp

Use the following properties when prompted:

groupId

:

packt.vaadin.datacentric.chapter01

artifactId

:

chapter-01

version

:

1.0-SNAPSHOT

package

:

packt.vaadin.datacentric.chapter01

IDEs such as NetBeans, Eclipse, and IntelliJ IDEA have excellent support for Maven. You should be able to create a new Maven project using the previous archetype in your IDE by providing the corresponding Maven coordinates without using the command line.

Clean up thepom.xml