Declarative UI for Vaadin Flow
Declarative UI for Vaadin Flow
This is basically Vaadin-8-style Declarative UI for Vaadin Flow. The goal is to externalize the layout of the components in your application and have it as much more readable HTML/XML instead of cluttering up your Java code. It's completely interpreted and converted to a Component-tree on the server-side.
Support for additional components and attributes can be added quite easily. The add-on comes with built-in support for Spring Boot to pick up custom ComponentFactory
and ComponentPostProcessor
beans.
For more details on why or how to use this add-on, please see the project page and/or take a look at the source code of the demo application.
See the Links section for add-ons that try to solve the same problem, albeit in completely different ways.
For Vaadin 14 support, see versions 0.x.
Sample code
// src/main/java/my/package/DemoView.java // imports omitted @Route("demo") public class DemoView extends TemplateComposite { /** * Created in the template and mapped to this field. */ @Mapped("shuffleButton") private Button shuffleButton; /** * Created here and mapped into the template. */ @Slotted("localeGrid") private Grid<Locale> localeGrid = new Grid<>(Locale.class); public DemoView() { } @Override protected void contentCreated() { localeGrid.removeAllColumns(); localeGrid.addColumn(Locale::toLanguageTag).setHeader("Language Tag"); localeGrid.addColumn("displayLanguage"); localeGrid.addColumn("displayCountry"); localeGrid.addColumn("displayVariant"); localeGrid.setDetailsVisibleOnClick(true); localeGrid.setItemDetailsRenderer(new ComponentRenderer<>(locale -> { LocaleDetails details = new LocaleDetails(); details.setLocale(locale); return details; })); shuffleButton.addClickListener(e -> shuffleLocales()); localeGrid.setItems(Locale.getAvailableLocales()); } private void shuffleLocales() { List<Locale> locales = Arrays.asList(Locale.getAvailableLocales()); Collections.shuffle(locales); localeGrid.setItems(locales); } @FragmentId("DetailsFragment") public static class LocaleDetails extends FragmentComposite { @Mapped("info") private TextField info; public void setLocale(Locale locale) { info.setValue(locale.getDisplayLanguage(locale) + " / " + locale.getDisplayCountry(locale) + " / " + locale.getDisplayVariant(locale)); } } }
<!-- src/main/resources/my/package/DemoView.html --> <vaadin-vertical-layout size-full> <slot name="localeGrid"></slot> <vaadin-button id="shuffleButton" theme="primary">Shuffle</vaadin-button> </vaadin-vertical-layout> <fragment id="DetailsFragment"> <vaadin-horizontal-layout width-full> <vaadin-text-field id="info" readonly width-full> </vaadin-text-field> </vaadin-horizontal-layout> </fragment>
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
- Released
- 2024-06-12
- Maturity
- STABLE
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 24.3+
- Vaadin 21+ in 2.1.3
- Vaadin 14+ in 0.9.0
- Vaadin 22+ in 2.2.4
- Vaadin 23 in 3.2.0
- Vaadin 24+ in 4.0.0
- Vaadin 24.1+ in 4.1.0
- Vaadin 24.2+ in 4.2.0
- Browser
- N/A
Declarative UI for Vaadin Flow - Vaadin Add-on Directory
Declarative UI for Vaadin FlowSimilar Project: SuperTemplate
Similar Project: HtmlTemplate
Demo Project
Source Code
Declarative UI for Vaadin Flow version 0.9.0
Declarative UI for Vaadin Flow version 0.9.1
Added error for missing slots. Renamed @Slotable to @Slotted. Slotable has a bit of a different meaning in Web Components.
Declarative UI for Vaadin Flow version 0.9.2 Declarative UI for Vaadin Flow version 0.9.3 Declarative UI for Vaadin Flow version 0.9.4 Declarative UI for Vaadin Flow version 2.1.3 Declarative UI for Vaadin Flow version 2.1.4 Declarative UI for Vaadin Flow version 2.2.4 Declarative UI for Vaadin Flow version 3.2.0 Declarative UI for Vaadin Flow version 3.3.2 Declarative UI for Vaadin Flow version 3.4.1 Declarative UI for Vaadin Flow version 4.0.0 Declarative UI for Vaadin Flow version 4.1.0 Declarative UI for Vaadin Flow version 4.2.0 Declarative UI for Vaadin Flow version 4.3.0 Declarative UI for Vaadin Flow version 4.3.1 Declarative UI for Vaadin Flow version 4.3.3
Supports and requires Vaadin 14.2 now. Added support for \ fragments.
* Supports Vaadin 14.4 now.
* Fix ClassNotFoundException when Vaadin Pro components are absent.
* Support child component handling in `ComponentPostProcessor`s. As a consequence the signature of a few methods needed to change. Should be easy to fix, though.
* Support new `HasHelper` interface.
* A general revision of stuff, which includes some more renaming, while we're at it. Mostly internal but some could affect devs (if there are any).
Reworked template fragments to greatly simplify usage.
* Supports and requires Vaadin 22.
* Improvements to fluent API.
* Added message dialog and general base class for dialogs.
* Several other minor improvements.
* Fixed handling of Scroller and its child component.
- https://gitlab.com/codecamp-de/vaadin-flow-dui/-/commits/release-2.2.4/
- Vaadin 23 is now required.
- Rework of `ComponentFactory`, `ComponentPostProcessor` and related classes. They're even simpler now, yet more powerful (default values, deprecated attributes, required attributes, aliases, ...).
- Added dynamic dev time view (`/component-declarations`) displaying actually supported components and attributes. Requires use of `@DuiComponent` by factories and post-processors.
- Allow to use components without factory.
- Improved error messages.
- Improvements to fluent API.
- Bug fixes and minor improvements regarding localization of certain components.
- Other minor improvements.
- Added support for MessageInput and MessageList.
- Add tests to improve and ensure consistency of fluent API.
- Determine and cache applicable factories and post-processors based on @DuiComponent annotations.
- Supports and requires Vaadin 24.