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
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. €18.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781849518802
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. €18.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 83.98
Vaadin 7 UI Design By Example: Beginner's Guide
€41.99
Vaadin 7 Cookbook
€41.99
Total 83.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.