Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Vaadin 7 Cookbook
Vaadin 7 Cookbook

Vaadin 7 Cookbook: Take the shortcut to developing rich internet applications in pure Java. Vaadin makes it easy and this cookbook makes it easier still with its practical recipes and straightforward approach.

eBook
$22.99 $32.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Vaadin 7 Cookbook

Chapter 2. Layouts

In this chapter, we will cover:

  • Creating an adjustable layout using split panels

  • Creating a custom layout

  • Controlling components over the CSS layout

  • Using CSS layouts for mobile devices

  • Binding tabs with a hard URL

  • Using Navigator for creating bookmarkable applications with back-forward button support

  • Aligning components on a page

  • Creating UI collection of components

  • Dragging-and-dropping between different layouts

  • Building any layout with AbsoluteLayout

Introduction


Layout management in Vaadin is a direct successor of the web-based concept for separation of content and appearance, and of the Java Abstract Windowing Toolkit (AWT) solution for binding the layout and user interface components into objects in programs. Vaadin layout components allow us to position our UI components on the screen in a hierarchical fashion, much as in conventional Java UI toolkits such as AWT, Swing, or SWT (Standard Widget Toolkit). This chapter describes a few of the practical concepts in the Vaadin framework. Layouting is comprehensive and could be published in a separate book. A lot of technical details are described in the Vaadin book on the web page: https://vaadin.com/book/vaadin7/-/page/layout.html.

Creating an adjustable layout using split panels


In a more complex layout, it is better to let the user adjust it. If we want to use a more flexible layout, we can use split panels. This recipe is about creating a complex layout with different components, for example, menu, editor, properties view, and Help view.

How to do it...

Carry out the following steps to create an adjustable layout:

  1. We create a simple Vaadin project with the main UI class called, for example, Demo:

    public class Demo extends UI {…}
  2. Our application will be based on split panels. As a main panel, we use HorizontaSplitPanel. This panel is divided into two areas. The first is on the left side, the second is on right the side.

    public class AdjustableLayout extends HorizontalSplitPanel {…}
  3. In the constructor, we set the properties of this main panel. On the left side we insert the main menu, on the right side we insert the other content. The left area will take 10 percent of the whole panel. And with the setSizeFull() method,...

Creating a custom layout


When we work on a complex web application, we need to cooperate with more people in the team. UX or graphic designers design layouts and for them it is more natural to design layouts using HTML and CSS. In such cases, we can use Custom layout that is described in the HTML template.

How to do it...

Carry out the following steps to create a custom layout:

  1. Create a project with the main UI class, Demo.

    public class Demo extends UI {…}
  2. First, we'll create an HTML template. Vaadin separates the appearance of the user interface from its logic using themes. Themes can include Sass or CSS style sheets, custom HTML layouts, and any necessary graphics. We'll call our template mylayout.html and place it under the folder layouts. In the WebContent folder we create this path of folders:

    WebContent/VAADIN/themes/mytheme/layouts
  3. Next, we define our layout. By setting the location attribute in the <div> element, we mark our specific areas. These elements will be replaced by Vaadin...

Controlling components over the CSS layout


In some cases, we need to control the CSS style of components programmatically. For example, when we want to create a cloud of the most searched terms or tags in our application, we need to change the size of each tag according to the number of searches. We'll use the CSS layout in that case. Our tag cloud will look like the following screenshot:

How to do it...

Carry out the following steps to create a cloud of tags using the CssLayout class:

  1. Create an application with the main UI class called, for example, Demo.

    public class Demo extends UI {…}
  2. We need our own label with the fontSize variable. We create a TagLabel class that extends Label.

    public class TagLabel extends Label {…}
  3. Next we add the fontSize attribute and the appropriate get method.

    private int fontSize;
    
    public int getFontSize() {
      return fontSize;
    }
  4. In the constructor we call the parent's constructor by super(text) and pass the value of fontSize. If we want to wrap labels on the line, we...

Using CSS layouts for mobile devices


Another nice feature of the CSS layout is that components are wrapped when they reach the width of the layout. This feature can be used to create layouts for small displays, for example, mobile phones or some tablets. We will create a simple layout with a header, two menus, and content in the middle of them.

As we can see in the following screenshot, if the user opens our application on a wide screen, components are displayed side by side. Except the header that takes up the whole width of the page.

If the user opens our application on a narrow screen, for example, on a mobile device, then all components will be aligned into the one column.

How to do it...

Carry out the following steps to create an application with a flexible layout for mobile devices:

  1. Create a project with the main UI class called, for example, Demo.

    public class Demo extends UI {…}
  2. We create a MobileLayout class that extends CssLayout.

    public class MobileLayout extends CssLayout {…}
  3. At first...

Binding tabs with a hard URL


If we have an application that works with bigger UI groups, it's nice to separate them with tabs. For example, we want to show different screens for our Contractors, Customers, Employees, and Help pages. The following screenshot shows the initial page of our application. We can see that the Home screen corresponds to the URL.

And if the user clicks on another tab, the URL has changed.

How to do it...

Carry out the following steps to create tabs bound with the URL:

  1. Create a project with the main UI class called, for example, Demo.

    public class Demo extends UI {…}
  2. We create a TabsURL class that extends TabSheet.

    public class TabsURL extends TabSheet{…}
  3. Now we create an array of UI group names.

    private static final String tabNames[] =
      {"Home", "Contractors", "Customers", "Employees", "Help"};
  4. We use these names for creating tabs. We insert the createTabs() method into our TabsURL class. Each tab contains a vertical layout with a big label according to the tab's name.

    private...

Using Navigator for creating bookmarkable applications with back-forward button support


Vaadin 7 has introduced a new capability for easy creation of bookmarkable applications with back and forward button support: the Navigator.

We will see how to use the Navigator class and what is needed to get it working. Navigator works with views, layouts that implement the View interface.

We are going to make an application with two views. We will be able to navigate between these two views with the back and forward buttons or make a bookmark.

The first view will be the welcome view, which we map to an empty URL fragment, so it becomes accessible at http://localhost:8080 address.

When a user clicks on the Open new Orders button, the orders view is displayed with the orders URL fragment.

How to do it...

Carry out the following steps to learn how to work with Views in Vaadin 7:

  1. Create a new Vaadin project with the main UI class called, for example, MyVaadinUI.

  2. Create the welcome view that will show a flattering...

Aligning components on a page


Aligning components is easy in Vaadin. We can align them on the left, on the right, on the top, on the bottom, and also center them vertically or horizontally. In this recipe, we will create a demo application in which we can see how aligning works. We will create three buttons in three different positions, as we can see in the following screenshot:

How to do it...

Carry out the following steps to create and learn how alignment works in Vaadin.

  1. We create a Vaadin project with the main UI class named Demo.

    public class Demo extends UI {…}
  2. We create a class called AligningDemo that is based on the VerticalLayout.

    public class AligningDemo extends VerticalLayout {…}
  3. In the constructor, we create and add all three buttons. The first button is placed on the top left side. We'll do it by the setComponentAlignment() method. As a parameter, we use predefined alignments from the Alignment class.

    public AligningDemo() {
      Button leftButton = new Button("top, left");
      addComponent...

Creating UI collections of components


Imagine that we need to create an editor for the UI design. What is it usually composed of? It's usually composed of the toolbar, editor, and a collection of components. In this recipe, we will create a UI collection of components. When we work with many components, it is good to group them by types. For grouping, we use the Accordion layout.

How to do it...

Carry out the following steps to create a UI collection of components:

  1. Let's create a new project and name the main UI class as Demo.

    public class Demo extends UI{…}
  2. We begin with the creation of a ComponentCollection class that extends the Accordion layout.

    public class ComponentCollection extends Accordion {…}
  3. For our example, we use icons from the internal Vaadin theme Runo because they are easily accessible using the ThemeResource class. They are divided into three groups by size. So we create two array variables.

    private String[] sizes = { "16", "32", "64" };
    private String[] icons = {
      "cancel.png...

Dragging-and-dropping between different layouts


Each layout has a different wrap behavior. If we want to try this behavior for ourselves, we will have to create a simple demo. In this demo, we can drag-and-drop components between the four different layouts. We can also change the size of each layout by moving the separator and watch how components are wrapped. If the line cannot be wrapped, a scroll bar appears.

How to do it...

Carry out the following steps to create a drag and drop panel:

  1. We create project with the root Demo class.

    public class Demo extends UI {…}
  2. All four layouts will be inserted into the DragndropPanel class that extends HorizontalSplitPanel.

    public class DragndropPanel extends HorizontalSplitPanel {…}
  3. Now let's insert the createLayout() method. In this method we add buttons to the layout that is taken over the AbstractLayout parameter. Next we wrap this layout by the DragAndDropWrapper class and set DropHandler. Here we implement two methods. First is getAcceptCriterion()...

Building any layout with AbsoluteLayout


If the basic layouts offered by Vaadin limit us, and we want to create some other special crazy layout, we can use AbsoluteLayout. There are no limits in this layout. We can insert components into any place we want. In this recipe, we will create a demo of a custom layout, Circle layout. There are also some reasons not to use AbsoluteLayout. They are described in the There's more... section at the end of this recipe.

How to do it...

Carry out the following steps to create a custom layout using the AbsoluteLayout class:

  1. We create a project with the main UI class called Demo.

    public class Demo extends UI {…}
  2. We will create a class called CircleLayoutDemo that extends AbsoluteLayout.

    public class CircleLayoutDemo extends AbsoluteLayout {...}
  3. Let's use icons from the Runo theme. So we create an array of icon names.

      private String[] icons = {
      "cancel.png", "calendar.png", "document.png",
      "email.png", "globe.png", "help.png",
      "note.png", "ok.png", "trash...
Left arrow icon Right arrow icon

What you will learn

  • Develop a Rich Internet Application in pure Java language.
  • Create a Vaadin project in different IDEs and platforms.
  • Explore the new Vaadin 7 features such as Extensions, URI fragments, Converter mechanism, and more.
  • Understand and use different types of layouts.
  • Use build-in atomic components such as button, table, text field, and more.
  • Bind model to components and fetch data from the database lazily.
  • Work with listeners and events and improve your web application by adding server-push add-ons.
  • Integrate Vaadin into the Grails framework.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 24, 2013
Length: 404 pages
Edition :
Language : English
ISBN-13 : 9781849518819
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 24, 2013
Length: 404 pages
Edition :
Language : English
ISBN-13 : 9781849518819
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 109.98
Vaadin 7 UI Design By Example: Beginner's Guide
$54.99
Vaadin 7 Cookbook
$54.99
Total $ 109.98 Stars icon

Table of Contents

12 Chapters
Creating a Project in Vaadin Chevron down icon Chevron up icon
Layouts Chevron down icon Chevron up icon
UI Components Chevron down icon Chevron up icon
Custom Widgets Chevron down icon Chevron up icon
Events Chevron down icon Chevron up icon
Messages Chevron down icon Chevron up icon
Working with Forms Chevron down icon Chevron up icon
Spring and Grails Integration Chevron down icon Chevron up icon
Data Management Chevron down icon Chevron up icon
Architecture and Performance Chevron down icon Chevron up icon
Facilitating Development Chevron down icon Chevron up icon
Fun Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(9 Ratings)
5 star 44.4%
4 star 44.4%
3 star 11.1%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer May 28, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Since the Kindle and print version of the books are separate items I've written a review of Vaadin 7 Cookbook here to have it in one place: http://bbissett.blogspot.com/2013/05/vaadin-7-cookbook.html (If linking to my external review is rude here, am happy to copy/paste and remove this).Summary (copied from blog):Overall, this is a great book of examples that cover a lot of common and not-so-common tasks in writing a Vaadin application. For the Vaadin newcomer, this book illustrates the power of the Vaadin framework very quickly. Reading it reminded me of how I felt when I first learned about Vaadin a thousand years ago. For the veteran developer, there will be things you haven't tried yet, especially if you're making the switch now from version 6 to 7.
Amazon Verified review Amazon
Peter Backx Jul 30, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The Vaadin 7 Cookbook is not a step by step guide to getting started with Vaadin. If you want that, Vaadin's own tutorials and book are more than enough. No need to buy another book.What sets this book apart are the many recipes that solve day-to-day problems you will encounter when developing a Vaadin application. A little experience with Vaadin and a little more experience with Java web applications is certainly going to help you enjoy the book. Furthermore, throughout the book, the authors give their opinion on what's the best way to tackle a problem. In fact, the architecture chapter is almost exclusively a summary of good ideas.This book can serve both as a reference for when you've actually got a specific problem. But it's also a good introduction to some of the new Vaadin 7 features and a treasure trove of small useful tips.So while you might be tempted to just glance over the book at first, it's definitely worth a read-through to pick up on all of the authors insights and practical knowledge.
Amazon Verified review Amazon
Marius Stancikas Jun 29, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is an excellent book for both beginners and more experienced Vaadin users. The book covers wide variety of topics from basics to more advanced topics. The book would be very useful for beginners as it starts with Vaadin basics and the complexity of the topics is increasing with every chapter. There are plenty of examples which are easy to follow. The book would be also handy for developers switching from Vaadin 6 to Vaadin 7. Even experienced Vaadin developers will find new and interesting stuff. So this is a must have for any Vaadin 7 developer.
Amazon Verified review Amazon
JM May 27, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am surprised with this book. There are just a lot of examples of my application needs. And a lot of real app's example code. If you are planing to use vaadin 7 you must buy it. If you want to give a try to vaadin 7 you must buy it too.
Amazon Verified review Amazon
C. Heartwell Mar 29, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I apologize that I am repeating this for all of the Vaadin books... these are good books to have if you use Vaadin, even if you take the training courses. Vaadin has become a great tool and it has a lot of features, not all of which you would discover without training, reading or browsing the API docs. And there are a lot of right ways and not-so-right ways to use Vaadin. You don't want to use Vaadin the "wrong" way. Use it right, and it pays off.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.