Blog

New ElementRequestHandler gives Vaadin component developers more control

By  
Matti Tahvonen
Matti Tahvonen
·
On Jul 2, 2025 3:13:43 PM
·
In Product

While it didn’t get much fanfare in the Vaadin 24.8.0 release notes, the new ElementRequestHandler is an impactful addition for advanced Flow component developers. It was introduced to support developing the revamped upload and download API. The feature quietly unlocks powerful capabilities for building custom components that require lower-level HTTP request handling—without relying on platform-specific workarounds or hacks.

Why it matters

Until now, component developers needing fine-grained control over HTTP interactions had to resort to brittle tricks or tie their components to frameworks like Spring Boot. ElementRequestHandler acts like a miniature, component-scoped servlet that can process direct HTTP requests tied to a specific instance of a component. You have full control of the traffic, whether you are sending or receiving data.

This isn't a feature you'll use in everyday application development. Instead, it’s a power tool for library and add-on developers building reusable components that push the boundaries of standard client-server communication in Vaadin.

What it does

Registering your ElementRequestHandle as an attribute to an Element, your client side code gets a unique URL where it can initiate HTTP requests. Implementation is almost like a good old HttpServlet, which you can typically express with a simple lambda. The framework handles the complex bits—like scoping the handler to the component's lifecycle and ensuring requests are only processed for the correct user and session context. This makes it both safe and intuitive to use when you truly need it. A simple example below.

```java
getElement().setAttribute("url", (ElementRequestHandler) (request, response, session, owner) -> {
  response.setContentType("text/html; charset=utf-8");
  response.getOutputStream().write(bytes);
});
```

Real-world use cases

This feature sure isn’t for every component—but when you're implementing something specialized, it can be essential. A couple of examples how I have already utilized it:

  • Enhanced Upload Component in Viritin: Previously dubbed the "upload done right," this custom upload component has long relied on unconventional internals to offer capabilities Flow’s native component lacked. With the 24.8 update, while the new Upload API still misses a few key features like true streaming and precise file size controls, ElementRequestHandler allowed the old hacky Viritin implementation to be greatly simplified and cleaned up.
  • Clipboard Workaround for Safari: Safari has some nasty “logic” with its clipboard permissions. In Safari, the item must be provided in a direct UI event handler, although the content can be generated asynchronously. By using ElementRequestHandler, a Flow component can provide clipboard contents through a user-triggered request—bridging a browser limitation with minimal effort. While simple String content could also use @ClientCallable, I took this approach so that I can later extend the utility for binary clipboard data like images.

Final thoughts

In short, ElementRequestHandler is not something that will change your day-to-day Vaadin development. But it can be  a major enabler for developers creating custom components. Especially if you are handling binary data or streams between client and the server, this feature gives you the flexibility and precision you’ve been waiting for.

See what else is new in Vaadin 24.8!

Matti Tahvonen
Matti Tahvonen
Matti Tahvonen has a long history in Vaadin R&D: developing the core framework from the dark ages of pure JS client side to the GWT era and creating number of official and unofficial Vaadin add-ons. His current responsibility is to keep you up to date with latest and greatest Vaadin related technologies. You can follow him on Twitter – @MattiTahvonen
Other posts by Matti Tahvonen