A collection of extension functions mimicking Vaadin 8 API but redirecting to Vaadin 14+ API where applicable.
This simplifies the process when rewriting Vaadin 8 components/layouts/view to Vaadin 14, since
you can continue using the same Vaadin 8 functions and get useful information and warnings.
For example,
there is setWidthUndefined()
function marked as deprecated (since it's no longer in Vaadin 14), redirecting to a setWidth(null)
call.
The jar is in Maven Central, so it's easy to add this library to your project.
Gradle:
repositories {
mavenCentral()
}
dependencies {
api("com.github.mvysny.karibu-migration:karibu-migration-MODULE:x.y")
}
Maven:
<dependency>
<groupId>com.github.mvysny.karibu-migration</groupId>
<artifactId>karibu-migration-MODULE</artifactId>
<version>x.y</version>
</dependency>
See the tag above for the latest version.
There are two modules available:
karibu-migration-common
module is pure Java, doesn't depend on Kotlin and brings in a set ofGridLayout
, HtmlSpan
, HorizontalSplitPanel
,NativeSelect
, RadioButtonGroupCompat
, SplitLayoutCompat
, VerticalSplitPanel
, LabelWrapper
and others.karibu-migration-kotlin
builds on karibu-migration-common
and adds lotsThe official Vaadin documentation on migration:
Usually, the upgrade is done one of the following ways:
In all cases, the application needs to be converted manually, view-by-view, to Vaadin 14.
Vaadin 8 apps and components were styled by adding rules to the global SCSS file, then adding styles to individual components. That is possible with Vaadin 14 as well, but there are very important distinctions:
ValoTheme.COMBOBOX_SMALL
is nowaddThemeVariants(ComboBoxVariant.Small)
; adding the ValoTheme.COMBOBOX_SMALL
via addClassName()
would have no effect.
addClassName()
addStyleName()
.I really urge you to read the Styling and Themes chapter, to familiarize yourself with the new concepts.
Vaadin 8's Valo theme has been replaced by Vaadin 14's Lumo theme. Theme parametrization is done via CSS Variables rather than the SCSS mechanism. Find more information here:
HasSize.setWidthUndefined()
is replaced by setWidth(null)
HasSize.setHeightUndefined()
is replaced by setHeight(null)
Component.setCaption()
is replaced by Component.setLabel()
from karibu-tools.
VerticalLayout
/HorizontalLayout
/FlexLayout
.LabelWrapper
component decorator from karibu-migration-common
.Component.getCaption()
is replaced by Component.getLabel()
from karibu-tools.CssLayout
is replaced by a Div
Component.setDescription()
is replaced by Component.setTooltip()
from karibu-tools, whichtooltip
DOM attribute. However this doesn't support tooltips with HTML;Component.getDescription()
is replaced by Component.getTooltip()
from karibu-tools, whichtooltip
DOM attribute.setStyleName()
replaced by setClassName
; addStyleName()
replaced by addClassName()
;removeStyleName()
replaced by removeClassName()
addStyleName(ValoTheme.*)
is generally replaced by addThemeVariants(XYZVariant.LUMO_*)
removeAllComponents()
- replace by removeAll()
addComponent()
- replace by add()
removeComponent()
- replace by remove()
It is discouraged to have a custom UI class. If this is necessary, it's better to
create a separate utility class and store it into the UI instance via ComponentUtil.setData(UI.getCurrent(), Util.class, util)
.
Alternatively see How to correctly extend a UI.
UI.getUiRootPath()
- prints the context root with the leading slash, e.g. /Gradle___karibu_helloworld_application_war
VaadinRequest.getCurrent().getContextPath()
.UI.setMobileHtml5DndEnabled()
- No longer necessary: mobile html 5 Drag'n'drop is enabled automatically on Vaadin 14+.setItemCaptionGenerator()
is replaced by setItemLabelGenerator()
addThemeVariants(ComboBoxVariant.Small)
instead of ValoTheme.COMBOBOX_SMALL
.addThemeVariants(ComboBoxVariant.AlignRight)
from karibu-tools instead of ValoTheme.COMBOBOX_ALIGN_RIGHT
addThemeVariants(ComboBoxVariant.AlignCenter)
from karibu-tools instead of ValoTheme.COMBOBOX_ALIGN_CENTER
ValoTheme.COMBOBOX_TINY
, ValoTheme.COMBOBOX_LARGE
, ValoTheme.COMBOBOX_HUGE
ValoTheme.COMBOBOX_BORDERLESS
.setEmptySelectionAllowed()
- When allowed
was set to true, the Vaadin 8 ComboBox used to show an additional itemnull
value. This is hard to emulate via DataProvider; thesetEmptySelectionCaption()
with setPlaceholder()
.setTextInputAllowed()
- no replacement. ComboBox always allows text input. Use Select
insteadscrollToSelectedItem()
- no replacement as of today. Please open a feature request at flow-components/issues.Also take a look at the ComboBox with Vaadin 8 behavior which closely mimics Vaadin 8 ComboBox.
setItemCaptionGenerator()
is replaced by setItemLabelGenerator()
There's also NativeSelect
Vaadin 14 component for your convenience, which simply
extends Vaadin 14's Select but provides all constructors from Vaadin 8's NativeSelect
.
setItemCaptionGenerator()
is replaced by setItemLabelGenerator()
setItemCaptionGenerator()
is replaced by setItemLabelGenerator()
from karibu-toolsOPTIONGROUP_SMALL
and OPTIONGROUP_LARGE
addThemeVariants(RadioGroupVariant.LUMO_VERTICAL)
ValoTheme.OPTIONGROUP_HORIZONTAL
.This project provides the RadioButtonGroupCompat
class which introduces a better Vaadin 8 compatibility:
setItemDescriptionGenerator()
setHtmlContentAllowed()
setVertical(boolean)
utility setter.It's not possible to have a single RadioButton just as it's not possible with Vaadin 8. See+vote for issue 1952. Workaround is to have a RadioButtonGroup with just one item.
Grid:
isSelectionAllowed()
- replace with isSelectionAllowed
from karibu-tools. EssentiallySelectionModel.Multi
or SelectionModel.Single
.Grid.addFooterRowAt(index)
- no replacement; the extension function calls either prependFooterRow()
or appendFooterRow()
.Grid.getFooterRowCount()
- replace with getFooterRows().size()
.Grid.getHeaderRowCount()
- replace with getHeaderRows().size()
.Grid.setExpandRatio()
- replace with setFlexGrow()
.Grid.Column:
Column.setDescriptionGenerator()
- no replacement. See issue #2315
Column.setExpandRatio()
- replace with setFlexGrow()
Column.getExpandRatio()
- replace with getFlexGrow()
Column.setCaption()
- replace with setHeader()
Column.getCaption()
- no replacement, see issue #1496
setWidth("50px").setFlexGrow(0)
.Column.setHidden()
- replace with setVisible()
Column.isHidden()
- replace with isVisible()
Column.setHidable()
- No replacement as of now; see+vote for issue #1603
Column.isHidable()
- no replacement as of nowaddContextMenuOpenListener()
has been replaced by addGridContextMenuOpenedListener()
.setDynamicContentHandler()
instead.The way how HorizontalLayout and VerticalLayout works has been changed completely. There is no slot mechanism anymore, and the layouting is now based on CSS Flexbox rather than on a Vaadin-specific JavaScript code. You need to relearn how CSS Flexbox works, then rework your layouts to work on top of CSS Flexbox. Docs to read:
API replacements:
setExpandRatio()
: replace with either expand()
(if the expand ratio is 1) or setFlexGrow()
addComponentsAndExpand()
: replace with addAndExpand()
A compatibility replacement components are coming, as a Vaadin Pro feature (TBA).
Please see the GridLayout
class providing Vaadin 8 API. Note that the new GridLayout
doesn't use slots and therefore uses different layouting engine. It's merely provided
as a best-effort.
Alternatively see the GridLayout from Vaadin Directory - it supports slots (which means positioning of children within allotted cells) but no expand ratios at the moment.
Label
is no longer a Div
but an actual <label>
element. Usually the best approach is
to replace label by Div
or Span
.
new Label("", ContentMode.HTML)
is replaced by new HtmlSpan()
from common
Label
with ValoTheme.LABEL_H1
is replaced by new H1()
; similar for H2
/H3
/H4
/H5
/H6
.ValoTheme.LABEL_HUGE
, ValoTheme.LABEL_LARGE
, ValoTheme.LABEL_SMALL
, ValoTheme.LABEL_TINY
- no replacements.ValoTheme.LABEL_BOLD
-> replace with getStyle().set("font-weight", "500")
ValoTheme.LABEL_LIGHT
-> used to set lighter text color and a font weight of 200, no replacement.ValoTheme.LABEL_COLORED
-> sets a blue text color #197de1
, no replacement.ValoTheme.LABEL_SUCCESS
/LABEL_FAILURE
used a green/red text color and a border, no replacement.ValoTheme.LABEL_SPINNER
-> use an indeterminate Progress Bar.Vaadin 8's CustomField
sets its width to 100% by default while Vaadin 10+'s CustomField
wraps its children by default.
Make sure to have your CustomField
implement HasSize
and call this.setWidthFull()
.
Not available directly. You can either build your own component out of Vaadin 14 Tabs
+Tab
(but that's just the tab header area), or try to use:
TabSheet
from karibu-migration-common
(a direct replacement)TabSheet
from karibu-dsl (the same thing but in Kotlin with DSL support)Use the VerticalSplitPanel
and HorizontalSplitPanel
classes extending the Vaadin 14 SplitLayout
providing the old Vaadin 8 API. Note that only Unit.PERCENTAGE
is supported -
trying to use Unit.PX
will fail with an exception.
Sorry, no replacement at the moment. TBD
Replace with MultiSelectListBox. There is also a ListSelect
component provided by karibu-migration-common
which mimics Vaadin 8 version.
setItemCaptionGenerator()
- implemented in ListSelect
; replaced by setRenderer(new TextRenderer<>(itemLabelGenerator));
. See+vote on issue #2601.ListBoxBase.setItemLabelGenerator()
.ClassResource
- replace with StreamResource
ThemeResource
- You have two options:
new Image("themes/my-theme/img/foo.png", "foo")
/frontend/themes/my-theme/img/foo.png
- Vaadin will copy the static resources/META-INF/VAADIN/webapp/VAADIN/static/themes/my-theme/img/foo.png
foldersrc/main/webapp
; the image would then go to src/main/webapp/img/foo.png
)new Image("img/foo.png")
.new Image("img/foo.png")
and not new Image("/img/foo.png")
new Image("./img/foo.png")
- the first one would not work with a non-empty context root@Route("my/nested/route")
.Licensed under Apache 2.0
Copyright 2021-2022 Martin Vysny
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
See Contributing.