Professional Documents
Culture Documents
Introduction <properties>
<maven.compiler.source>1.8</maven.compiler.source>
This reference card is tailored to developers with previous Vaadin <maven.compiler.target>1.8</maven.compiler.target>
experience. It is a quick reference on key concepts and everyday tasks <failOnMissingWebXml>false</failOnMissingWebXml>
that arise while using the framework. For a comprehensive reference or </properties>
tutorials to learn Vaadin, see the links in the Useful links section. <dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-core</artifactId>
Useful links <version>14.2.0</version>
</dependency>
Learn: https://vaadin.com/docs
</dependencies>
Follow tutorials: https://vaadin.com/tutorials
</project>
Create new projects: https://vaadin.com/start
Edit a theme: https://demo.vaadin.com/lumo-editor
Search Vaadin Icons: https://vaadin.com/components/vaadin-icons/
MainView.java:
html-examples
Search UI components: https://vaadin.com/components import com.vaadin.flow.component.Text;
public MainView() {
}
pom.xml:
<project xmlns=”http://maven.apache.org/POM/4.0.0”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.
apache.org/xsd/maven-4.0.0.xsd”>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
VA A D I N 1 4 R E F E R E N C E C A R D - 2
element.
HasEnabled Enables or disables setEnabled
HasElement).
HasComponents). getComponentCount
Input getComponentAt
Accordion, Button, ContextMenu, Details, Dialog, Grid, Icon, HasStyle Enables CSS styles and CSS addClassName
Div, Span, Section, Header, Footer, Article, H1, H2, H3, removeClassNames
getStyle
H4, H5, H6, Paragraph, Label, Anchor, OrderedList, ListItem,
HasText Enables text content. setText
Image, DescriptionList, Emphasis, Hr, IFrame, Input, Main,
getText
NativeButton, Nav, Pre, Section, UnorderedList.
HasTheme Enables theming. addThemeName
removeThemeName
setThemeName
Layouts
getThemeName
VerticalLayout, HorizontalLayout
FlexLayout
Alignment
VerticalLayout, HorizontalLayout, FlexLayout
VerticalLayout, HorizontalLayout
FlexLayout
setAlignContent(ContentAlignment) Sets how the “lines” within
the layout are aligned when
there is extra space. See the
ContentAlignment enum values.
VA A D I N 1 4 R E F E R E N C E C A R D - 4
RouteConfiguration.forSessionScope().setRoute(“view”,View.class);
Parameters
@Route(“”)
implements HasUrlParameter<String> {
@Override
String parameter) {
.getQueryParameters()
.getParameters()
.get(“name”)
.get(0);
AppLayout
Two-way data binding. Sets the bean values in the input fields and sets
values in the bean when the input fields values change:
Interface Description
binder.setBean(person);
BeforeLeaveObserver Allows delaying or canceling the navigation, or
BeforeLeaveListener changing the navigation to a different destination.
One-way data binding. Sets values from the bean to the input fields:
Reroute with the BeforeLeaveEvent::reroute() methods.
Reroute and update the browser URL with the binder.readBean(bean);
BeforeLeaveEvent::forward() methods.
BeforeEnterObserver* Allows changing the navigation to a different One-way data binding. Sets values from the input fields to the bean:
BeforeEnterListener destination. binder.writeBean(bean);
Reroute with the BeforeEnterEvent::reroute() methods.
Reroute and update the browser URL with the
BeforeEnterEvent::forward() methods.
Gets the bean:
AfterNavigationObserver
Person person = binder.getBean();
Allows updating parts of the UI once the navigation
AfterNavigationListener has been completed.
Advanced usage
* Needs to be defined in a UI init listener if you want it to run before any
binder.forField(ageTextField)
views are created, for instance for general access control.
.asRequired(“Is required”)
“Must be an integer”))
...
new Binder<>(Person.class); // property names supported } catch (ValidationException e) {
new Binder<>(); // property names not supported ...
if (binder.validate().isOk()) {
TIP: Use the writeBeanAsDraft(BEAN) and writeBeanIfVal-
...
id(BEAN) methods when needed.
}
Basic configuration
Or:
binder.bind(
textField,
);
@Override
Using the Vaadin Session protected void servletInitialized() throws ServletException {
super.servletInitialized();
implements VaadinServiceInitListener {
@Override
event.addBootstrapListener(response -> {
VaadinSession.getCurrent() });
});
getSession().invalidate(); }
implements VaadinServiceInitListener {
@Override
initEvent.getSource().addSessionDestroyListener(
sessionEvent -> {
});
}
VA A D I N 1 4 R E F E R E N C E C A R D - 7
} CSS (PROJECT_ROOT/frontend/css-file.css):
@Override .css-class-name {
protected void onDetach(DetachEvent detachEvent) { ... custom css rules ...
...custom logic when the component is detached from the }
UI...
}
Java (View.java):
} ...
@CssImport(“./styles/css-file.css”)
button.addClassName(“css-class-name”);
Heartbeat }
}
The objective of the heartbeat mechanism is to remove UI instances that
are no longer active in the same session.
The client side sends keep-alive heartbeat requests at a configurable Shadow DOM
rate. A UI expires if three consecutive heartbeats are missed. Vaadin components are web components in the client side. The cli-
ent-side implementation is encapsulated inside the Shadow DOM.
NOTE: The HTTP session doesn’t expire if there is a browser window
open. This is a side effect of the heartbeats. Use the closeIdleSes- Java:
sions configuration parameter to override this behavior.
@CssImport(value = “./styles/styles.css”, themeFor = “vaadin-
button”)
Static content
NOTE: Only works for web components that implement vaadin-the-
Templates, CSS, Javascript, images:
mable-mixin.
WAR src/main/webapp/frontend/
CSS (styles.css):
JAR src/main/resources/META-INF/resources/frontend/
[part=”label”] {
Favicon:
… custom CSS ...
}
WAR src/main/webapp/icons/icon.png
JAR src/main/resources/META-INF/resources/icons/icon.png
TIP: Use the browser inspector to see the available parts of a web
NOTE: These resources are not bundled. component
NOTE: A production build is necessary to deploy to external servers. sendUrlsAsParameters Enables or disables sending of URLs as GET and
POST parameters in requests with content type
application/x-www-form-urlencoded.
Maven profile (all Vaadin starters include this profile):
pushLongPollingSuspendTimeout Long poll push strategy timeout in milliseconds
<profile>
maxMessageSuspendTimeout Maximum time in milliseconds that the client will
<id>production</id> wait for the predecessors of a received out-of-
<properties> order message.
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>