Skip to content

Instantly share code, notes, and snippets.

View TatuLund's full-sized avatar

Tatu Lund TatuLund

View GitHub Profile
@TatuLund
TatuLund / ConditionalFieldView.java
Last active April 17, 2026 07:28
Handling conditionally appearing and disappearing fields in Vaadin is trickier than in desktop frameworks like Swing. This is due to fact we have now a distributed system with server and client component. But there are some mechanisms that can be used to deal with the cases like this. The server does not even need to be slow in order to replicat…
package com.example.application.views;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.theme.lumo.LumoUtility;
@TatuLund
TatuLund / DateTimePickerView.java
Created March 30, 2026 08:29
There are couple of features missing in Vaadin 24 DateTimePicker. 1: There is no automatic setting of time mode, which would be useful in some cases, 2: The time picker does not autoscroll to selected time if such exists. This Gist demonstrates JavaScript workarounds for these missing features.
package com.example.application.views;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import com.vaadin.flow.component.datetimepicker.DateTimePicker;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
@TatuLund
TatuLund / LazyDrillDownView.java
Created January 19, 2026 07:59
Example of how to implement lazy drill down with Vaadin Charts using Vaadin 24.9
package com.example.application.views;
import java.util.HashMap;
import java.util.Map;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.charts.Chart;
import com.vaadin.flow.component.charts.model.AxisType;
import com.vaadin.flow.component.charts.model.ChartType;
import com.vaadin.flow.component.charts.model.Configuration;
@TatuLund
TatuLund / GridManualPagination.java
Created May 8, 2025 07:03
There is no paged Grid variant in Vaadin framework yet. However it is possible to do it using custom data provider. This is an example of wrapping paged data provider in GridPager utility class which can be used with given Grid. This makes the utility general purpose and can be used with extended Grid components such as GridPro, SelectionGrid an…
package com.example.application.views;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
@TatuLund
TatuLund / RichTextEditorView.java
Created March 7, 2025 11:07
Vaadin's RichTextEditor does not have label, errorText, invalid styles and helperText. CustomField is the simplest way to add those, here is example RteField
package com.example.application.views;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import com.vaadin.flow.component.Html;
import com.vaadin.flow.component.checkbox.Checkbox;
import com.vaadin.flow.component.customfield.CustomField;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.richtexteditor.RichTextEditor;
@TatuLund
TatuLund / BlockingDialogView.java
Created November 28, 2024 09:05
One very common challenge that occurs when migrating from Swing to Vaadin is that blocking dialog is very common pattern in Swing. That is possible there, because Swing application is single threaded and non-distributed. Vaadin application has UI running in browser making it distributed system. Hence blocking dialog is not a natural concept. The…
package com.example.application.views;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.DetachEvent;
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.UIDetachedException;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.notification.Notification;
@TatuLund
TatuLund / SpringDemoView.java
Created July 8, 2024 12:09
This is a DemoView and helper class for Spring Boot based (WAR packaging required) projects to show demo code snippets.
package com.example.application.views;
/*
* Copyright 2000-2021 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@TatuLund
TatuLund / SpinnerButton.java
Created June 11, 2024 05:37
Accessibility makes things less obvious. It is trivial to use Spinner in Button component by just using button.setIcon(new Spinner()). But that is not accessible. Spinner does have aria alert label, but it wont be announced when Spinner is a child of disabled button. Hence Spinner needs to be placed outside button. Here is an example how to do it.
package org.vaadin.addons.componentfactory.spinner;
/*
Add this depenency to get Spinner component
<dependency>
<groupId>org.vaadin.addons.componentfactory</groupId>
<artifactId>spinner</artifactId>
<version>24.1.0</version>
</dependency>
@TatuLund
TatuLund / SecurityConfiguration.java
Created June 10, 2024 08:44
An example how to configure SpringSecurity SessionConcurrency with VaadinWebSecurity. This is a built-in feature in SpringSecurity which can be used for example to allow the same user to login only once at the time in the system. When you try to login on another computer you will be given an error until you logout from the previous one. I.e. one…
package org.vaadin.example;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.core.session.SessionRegistryImpl;
@TatuLund
TatuLund / GridColumnWidths.java
Last active June 18, 2024 06:48
Vaadin 24 uses only a small fraction of the rows to autocalculate column widths, as it would be too slow otherwise. Your Grid may have long and short data scattered around in the Grid, hence the calculation based on the first rows may not be good for the whole Grid. Then it would be nice to recalculate the widths when Grid is being scrolled to n…
package com.example.application.views;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;