Build your main view

Now that you have IntelliJ IDEA or Eclipse running and a project available, we can take start building our first view with Designer.

To do this:

  1. Delete MainView.java in src/main/java/com/vaadin/tutorial/crm/ui.

  2. In the Project tree, expand the frontend/src folder.

  3. Right click the frontend/src folder and select New > Directory. Name the new folder views.

  4. Right click the newly-created views folder and select New > Vaadin 10+ Design.

  5. In the Name field, type main-view.

  6. Make sure the Create Java companion file checkbox is checked. This allows us to bind data and add listeners to our view in Java.

  7. In the Java package field, click the folder selection button and navigate to com.vaadin.tutorial.crm.ui.

Creating a new Lit view.
New Vaadin 10+ design dialog
Tip
The Template type option allows selecting between Lit template in TypeScript (default) or Polymer template in JavaScript.

Click OK to generate the files.

Vaadin Designer will open in Google Chrome.

Warning
Gradle based projects
Gradle based projects (see Starting a Project with Gradle for more information) need to be started at least once before using Designer, so that the frontend dependencies (in the node_modules folder) are ready for Designer.

Getting familiar with the UI

Designer consists of four main parts:

  • Paper is where the UI you are building renders. It shows you how your view will look like. Before you add components to your view, the paper proposes a set of starting points for your newly-created view.

  • Palette is a list of components that are available for use. The list is divided into multiple sections:

    • HTML elements are the built-in elements of the HTML language, like <p>, <h1> and <div>.

    • Parts is a list of all available web components in your project. These are scanned automatically from the node_modules folder in your project. When you add new 3rd-party web components to your project, they show up in the list and are available for use.

    • Components are snippets for Vaadin’s components that give you handy, commonly-used configurations, like having a button with an icon and caption.

    • Project components are the other designs in your project. You can include them in your current view.

  • Outline shows you what components are in use in the view and their hierarchy.

  • Properties is where you modify how a single component looks and behaves.

Creating the main layout

This is the layout which we will build.

A web application with a listing of contacts and an editor open.

From the image, you can see we need:

  • A vertical layout at the root of the view.

  • A horizontal layout with a text field for filtering, as well as a button to add new entries, at the top.

  • A horizontal layout for a grid of data entries and a form below.

We’ll disregard the form for now, as we build it separately after adding the other components to the view.

Adding the components

  1. On the paper, click Vertical to get a vertical layout as your starting point. Your view now consists of an empty layout.

  2. Find Horizontal Layout Spacing in the palette and drag it onto the vaadin-vertical-layout on the paper twice. You can use the search field at the top to find components easily.

  3. Find Vaadin Text Field in the palette and drag it onto the first vaadin-horizontal-layout.

  4. Find Button in the palette and drag it onto the first vaadin-horizontal-layout.

  5. Find vaadin-grid in the palette and drag it onto the second vaadin-horizontal-layout.

Components added to the view.

Our view does not look as planned yet, but it does have the components we need. We’ll now continue to configure the components to get it to look like we want.

Configuring the main layout

In the main layout, we need to add a bit of space between the components, as well as around the layout, to make it look better:

  1. Select the top-level layout, by clicking anywhere in the empty space of the vertical layout.

  2. In the properties view, in the Size and space panel, open the Padding selector and select M. This adds some space around the main layout, giving the design room to "breath".

  3. In the same panel, open the Spacing selector and select M. This adds space between the toolbar and the grid.

Spacing and padding added to the main layout.

Configuring the toolbar

For the toolbar, we need to configure a text field:

  1. Select the text field.

  2. In the properties view, under attributes, find the label attribute and remove the value from it. We do not need a separate label as we have the description as the placeholder value for the field.

  3. In the properties view, under attributes, find the placeholder attribute and replace "Placeholder" with "Filter by name…​".

  4. In the properties view, under attributes, find the clear-button-visible attribute and enable the checkbox. This gives the user an easy way to clear the filter.

  5. Select the button.

  6. In the properties view, find the text panel at the top and replace the default "Button" text with "Add contact".

Configured toolbar.

Making the Grid fill the available space

To show as much data as possible, we want to give the Grid the rest of the screen space:

  1. Select the lower horizontal layout, vaadin-horizontal-layout.

  2. In the properties view, in the Size and space panel find the width and height fields and choose "100%" in both. This expands the layout to take up all the available space.

  3. Select the Grid, vaadin-grid.

  4. In the properties view, in the Size and space panel set the width and height fields to "100%". This gives all the space in the layout to the grid.

Filled toolbar.

Our main layout is now looking great, but it is still missing the form. Proceed to the next chapter to add one: Build your contact form

Updated 2022-01-05