Using Vaadin Components

There is a set of pre-built server-side components with Java API for Vaadin Web Components, such as Button, TextField and so on. Those components are part of the Vaadin platform, and are included as dependencies in the platform together with Flow.

The platform has the following components with Java API available:

When you use the Vaadin 10 platform dependency, you automatically get ALL available components. Using the platform dependency guarantees that you’ll get versions of Flow and the components that are compatible together.

XML

  1. <repositories>
  2. <repository>
  3. <id>vaadin-prereleases</id>
  4. <url>https://maven.vaadin.com/vaadin-prereleases</url>
  5. </repository>
  6. </repositories>
  7. <dependencies>
  8. <!-- other dependencies -->
  9. <!-- component dependency -->
  10. <dependency>
  11. <groupId>com.vaadin</groupId>
  12. <artifactId>vaadin</artifactId>
  13. <version>${vaadin.platform.version}</version>
  14. </dependency>
  15. </dependencies>
Note
vaadin.platform releases regularly and you can check the version number here
Note
The components are also provided as single dependencies per component. See the platform pom.xml for example.

The platform also contains ready made theming for the components that help you tweak and tune the look and feel of the components. See the Using Component Themes for more info.

For more ready-made Java APIs for Web Components, you should check the Vaadin Directory.

Flow Component Package Contents Explained

A Flow component package consists of two main sections:

  • Java API classes

  • Web Components’ files (html, js, css etc)

All sections are used by Flow to display the components in web pages correctly. By default, both sections are provided in the same jar.

Web components’ files are provided as webjars – jar files that contain webcomponents’ files, heavily influenced by current Polymer package manager: bower (not developed or maintained by Vaadin)

Webjars are designed to replace bower usage by using Maven for the same purposes.

Flow is able to resolve requests into webjars’ contents (if intended by request), imitating the regular web component’s files.

Although currently enabled by default, webjars do not restrict users from using external web components’ files:

  • webjar resolving can be turned off

  • if no suitable webjar is found, request resolving falls back to configured external web components’ locations

Note
Due to current webjar limitations, extra maven configuration (extra repository + bom file declaration) is required.

Maven configuration to use only single components

If you don’t want to take everything provided by the com.vaadin:vaadin dependency, you can also optionally declare single components as dependencies.

The first step is to add the bom and the wanted flow-component (e.g. vaadin-button-flow) package to your project dependencies.

When using Maven you can add a the button component into your pom.xml as this:

XML

  1. <repositories>
  2. <repository>
  3. <id>vaadin-prereleases</id>
  4. <url>https://maven.vaadin.com/vaadin-prereleases</url>
  5. </repository>
  6. </repositories>
  7. <dependencyManagement>
  8. <dependencies>
  9. <dependency>
  10. <groupId>com.vaadin</groupId>
  11. <artifactId>vaadin-bom</artifactId>
  12. <version>${vaadin.platform.version}</version>
  13. <type>pom</type>
  14. <scope>import</scope>
  15. </dependency>
  16. </dependencies>
  17. </dependencyManagement>
  18. <dependencies>
  19. <!-- other dependencies -->
  20. <!-- component dependency -->
  21. <dependency>
  22. <groupId>com.vaadin</groupId>
  23. <artifactId>vaadin-button-flow</artifactId>
  24. </dependency>
  25. <!-- other dependencies -->
  26. </dependencies>

Maven configuration to exclude webjars

If webjar dependencies are not needed, they can be excluded from the project using standard Maven mechanism:

XML

  1. <!-- No webjars == no bom needed and no extra repo needed, but you have to get webjars' files into the build yourself -->
  2. <dependencies>
  3. <!-- other dependencies -->
  4. <!-- the dependency with webjars excluded -->
  5. <dependency>
  6. <groupId>com.vaadin</groupId>
  7. <artifactId>vaadin-button-flow</artifactId>
  8. <version>1.0-SNAPSHOT</version>
  9. <exclusions>
  10. <exclusion>
  11. <groupId>org.webjars.bowergithub.vaadin</groupId>
  12. <artifactId>*</artifactId>
  13. </exclusion>
  14. </exclusions>
  15. </dependency>
  16. <!-- other dependencies -->
  17. </dependencies>