This repository contains a tutorial on how to create a simple CRUD view for managing a list of orders. The example is structured as a sequence of steps, where each commit represents an incremental change to a Vaadin starter, and each tag represents a milestone through the tutorial.
You can run the application by using mvn spring-boot:run
or directly by running the Application class from your IDE, then open http://localhost:8080/ in the browser.
-
Download the Vaadin 10 Project Base Starter with Spring.
-
Import the project to the IDE of your choosing as a Maven project.
-
Add entities and repository classes (for this example, our "repository" is just an in-memory list).
-
Add fields, grid and buttons.
-
TAG step-1 Now we have the UI components, but no behaviors.
-
Instantiate a
Binder
and define bindings for each field. -
TAG step-2 At this point we have some validations (provided by
Binder
) but we cannot add new orders. -
Autowire the repository, so that it can be used from the view.
-
Add a click listener to the OK button, so that when the user clicks the button a new row is added into the grid, based on the filled values.
-
TAG step-3 Now, new orders can be added to the grid (but after the user adds an order, the input fields remains filled, and if the user clicks the OK button again a duplicate order will be saved).
-
Add a
clearForm
method that updates theBinder
with a new instance ofOrder
inPENDING
state. -
Add a click listener to the Cancel button, that invokes
clearForm
. -
Invoke
clearForm
from the OK button's click listener, after the new order has been saved. -
TAG step-4 Now the form fields are cleaned after the user clicks on either OK or Cancel button, but we cannot edit existing items.
-
Add a grid selection listener that loads the value of the selected row into the
Binder
(if no row is selected, callclearForm
so that the fields are set to their initial state). -
Modify the OK click listener: if a row is selected, then update it with the new values.
-
Add a DELETE action in the
Grid
. -
Add a renderer for the "priority" column.
-
TAG step-5 The end result.