Table of contents
1.
Introduction
2.
Configuration Properties
2.1.
Using System Properties
2.2.
Using Servlet Initialization Parameters
3.
Frequently Asked Questions
3.1.
What is Maven?
3.2.
Why do we use the Rich Text Editor component of Vaadin?
3.3.
Why do we prefer Production Mode?
3.4.
Briefly explain PWA.
4.
Conclusion
Last Updated: Mar 27, 2024
Easy

Configuration Properties

Author Rupal Saluja
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Vaadin is a web application development platform for Java that encourages developers to use Java as their programming language to develop various User Interfaces (UIs) without the compulsion of direct usage of HTML and JavaScript. 

The platform includes a set of web components, a Java-based web framework, and a set of tools enabling the implementation of modern web Graphical User Interfaces (GUI). The implementation can be done using Java only, TypeScript only, or both.

why Vaadin

This platform comes with certain properties, known as Vaadin Configuration Properties, that can be used to change the behavior of Vaadin applications. These properties will be discussed in this blog ahead.

Vaadin logo

Configuration Properties

At the very moment when you hear the term Configuration Properties, the first that comes to our mind is that it can be such properties that are used to configure, that is, to alter the behavior. The concept is very similar here. The Configuration Properties of Vaadin help users configure the outlook of Vaadin Applications. You will always have the option to use either System properties or servlet initialization parameters to set them. 

Configuration properties

There is a list of properties that are available, especially for Configuration purposes. These properties are defined in the com.vaadin.server.DeploymentConfiguration and com.vaadin.server.Constants classes. We will discuss them all ahead in detail.

✍️ closeIdleSessions

This property will close all the sessions which are not in use, that is when no UI is active. As far as there is an open UI, the session is not idle, hence, it will not expire, even if there is zero user interaction. This property is set to false by default. It works only when you control its behavior and set an init parameter named closeIdleSessions to be true.

✍️ devmode.liveReload.enabled

When you break this property’s name, it says developer’s mode live Reload enabled. This means that if you are using any live reload tool on the server’s side, the browser will be refreshed automatically by itself after the code gets reloaded on the server side. This property is set to true by default.

✍️ devmode.sessionSerialization.enabled

Again, if you break the property’s name, you will have a clear idea of what this property is going to do. It says developer’s mode session serialization enabled. By default, it is false. In such a situation, only other HTTP session data is serialized or deserialized on the development server restart. When set to true determines whether or not the VaadinSession instances of the users running in development mode are serialized on the server. 

✍️ devmode.optimizeBundle

This property will optimize webpack bundles in the developer’s mode. The default is set to true. In such a situation, a webpack bundle is generated in the development mode in which all the resources found on the classpath are included. The optimized bundles created are used from the application entry points. These bundles use bytecode scanning, which in turn increases the startup time.

✍️ disable.automatic.servlet.registration

This configuration property specifies whether or not Vaadin should automatically register servlets needed for the application to work or not. It is actually a parameter that permits Vaadin for automation.

✍️ disable-xsrf-protection

This kind of protection is enabled by itself, but it needs to be disabled to order to enable certain another kind of testing. It is a cross-site request forgery protection and can be disabled by setting the init parameter. 

✍️ frontend.url.es5

This property is used only when the requests come from older browsers that do not support ES6, which is the default version of the web component development language. Vaadin searches for this location, that is, ES5, of Web component files in the production mode in the case of non-modern browsers.

✍️ frontend.url.es6

This property is used when the requests are from modern browsers that support ES6, which is the version of the web component development language, that is set by default. Vaadin searches for this location in the case of real-time browsers.

✍️ heartbeatInterval

Interfaces that are open on the client side will send a regular heartbeat to the server. This indicates that UIs are still alive, even if there is no recent user interaction. In case the server is not receiving a valid heartbeat for any given UI, that UI will be removed from that session eventually.

✍️ i18n.provider

This property facilitates i18n implementation. The application only needs to implement the i18n provider and define the fully qualified class name in this property to use localization and translation strings.

✍️ load.es5.adapters

For browsers that do not support ES6, which is the default version of the web component development language, their initial pages need some extra web components and libraries to work. These extra web components and libraries are known as polyfills which need to be loaded in such situations.

✍️ maxMessageSuspendTimeout

This property specifies the maximum time for which the client will wait before considering any message suspended or missing. If the message is found to be suspended or missing, then a full resynchronization of the application is requested. The default value for the maximum time is 5000ms.

✍️ original.frontend.resources

This configuration property determines whether Vaadin should use frontend resources or not, that is, Vaadin should have access to bundled web fragments or not.

✍️ pnpm.enable

It is one of those configuration properties that is used to enable pnpm instead of npm so that the front-end dependencies can be downloaded and resolved. By default, this property is set to false and npm is used. It has to be set to true to enable this property.

✍️ productionMode

This property sets the application to work in the production mode.

In Production Mode, most of the logged information that appears on the console is disabled. This is because logging and other debug features can have a non-negligible impact on the performance of the application.

✍️ pushLongPollingSuspendTimeout

If you break the property’s name, it says that this property specifies the maximum time, in milliseconds, for which responses are accepted after each network request while using the long polling transport strategy.

✍️ pushMode

This property determines which notifications can be pushed. The two permitted values are disabled or manual.

✍️ pushURL

This configuration property works similarly to the pushMode property. The only change is that in this property, a URL is needed to push requests. This is because some servers require a predefined URL to push notifications.

✍️ requestTiming

By default, this property is set to false. If set to true, it allows the server to include some basic timing information in every response. This property is used basically for performance testing of the application.

✍️ sendUrlsAsParameters

This property returns URLs as GET and POST parameters with content type application/x-www-form-urlencoded, if enabled. 

✍️ syncIdCheck

This property returns whether the syncId is enabled or not. 

Basically, a sync ID is needed to handle such situations when any client sends a message to the connector that has been removed from the server recently.

✍️ useDeprecatedV14Bootstrapping

It is one of many configuration properties that is used for enabling the server-side bootstrapping mode. This mode was used in Vaadin 14 and versions earlier than that.

Using System Properties

Ways to configure properties

One of the ways to configure Vaadin applications is by using system properties. While using Java’s System Properties to configure the Vaadin application parameters, the prefix ‘vaadin.’ needs to be specified always before the parameter names. An instance of setting a system property when the execution of the Maven goal is being done is given below.

mvn jetty:run -Dvaadin.frontend.url.es6=http://mydomain.com/es6/ -Dvaadin.frontend.url.es5=http://mydomain.com/es5/

 

The System properties can also be configured for Mavin plugin executions. An example under XML extension to set a Vaadin-specific system property while running Jetty Mavin plugin is given below.

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <configuration>
        <systemProperties>
            <systemProperty>
                <name>vaadin.pushMode</name>
                <value>disabled</value>
            </systemProperty>
        </systemProperties>
    </configuration>
</plugin>

Using Servlet Initialization Parameters

Ways to configure properties

Another way to configure Vaadin applications is by using servlet initialization parameters. The Servlet 3.0 @WebServlet annotation is used for this alternative to work. It requires you to configure your own servlet using the above-mentioned annotation or it will be done by Vaadin itself. If done automatically by Vaadin, it uses default parameter values. An example of this automated Servlet Initialization under the Java extension is shown below.

@WebServlet(urlPatterns = "/*", name = "myservlet", asyncSupported = true, initParams = {
        @WebInitParam(name = "frontend.url.es6", value = "http://mydomain.com/es6/"),
        @WebInitParam(name = "frontend.url.es5", value = "http://mydomain.com/es5/") })
public class MyServlet extends VaadinServlet {
}

 

There will always be an option to use a web.xml file to get the same results. An XML code for Servlet Initialization is given below.

<?xml version="1.0" encoding="UTF-8"?>
<web-app
  id="WebApp_ID" version="3.0"
  xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">


  <servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>
        com.vaadin.flow.server.VaadinServlet
    </servlet-class>


    <init-param>
      <param-name>frontend.url.es6</param-name>
      <param-value>http://mydomain.com/es6/</param-value>
    </init-param>


    <init-param>
      <param-name>frontend.url.es5</param-name>
      <param-value>http://mydomain.com/es5/</param-value>
    </init-param>
  </servlet>


  <servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

Frequently Asked Questions

What is Maven?

A maven is a tool that facilitates build automation, mainly used for Java projects. It addresses two phases of software building, which are, the process of building software and its dependencies. In Vaadin, its Maven Plugin contains configuration for almost every configuration property. 

Why do we use the Rich Text Editor component of Vaadin?

The Rich Text Editor component allows you to enter rich text. By Rich Text, we mean it facilitates users to format and style their text using advanced formatting, that is, boldface, italics, headings, lists, images, links, etc.

Why do we prefer Production Mode?

In Production Mode, development-mode JavaScript functions are not exported, the push is taken as a minified JavaScript file instead of full, static resources are cached, and logged information doesn’t appear on the console. These are the reasons why we prefer the production mode.

Briefly explain PWA.

In Vaadin, PWA stands for Progressive Web Application. Some extra configuration is used to enable Vaadin to run as a Progressive Web Application (PWA). It aims to give a similar experience as a Native application, but with a user-friendly installation flow and a capability to work offline.

Conclusion

In a nutshell, we understood what configuration properties were and learned about several configuration properties available to us. We also saw two approaches to configure such properties, that is, either by using System Properties or by using Servlet Initialization Parameters.

We hope the above discussion helped you understand Vaadin Configuration properties in clearer terms and can be used for future reference whenever needed. If you want to know the 15 best Java Frameworks, you can read our blog on the 15 best Java Frameworks. To learn more about Vaadin and its components, you can refer to blogs on  Vaadin-Core ElementsVaadin-AvatarVaadin-Dialog, and Security practices at Vaadin.

Visit our website to read more such blogs. Make sure that you enroll in the courses provided by us, take mock tests and solve problems available and interview puzzles. Also, you can pay attention to interview stuff- interview experiences and an interview bundle for placement preparations. Do upvote our blog to help fellow ninjas grow.

Happy Coding!

Thankyou
Live masterclass