question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FUSION] Messages from the form validation are not interpolated

See original GitHub issue

Description of the bug / feature

When I’m validating a form I want to use the same message in the frontend and in the backend.

Minimal reproducible example

You can check this repository: https://github.com/jcgueriaud1/vaadin-multilanguage-app Especially in Person bean: https://github.com/jcgueriaud1/vaadin-multilanguage-app/blob/main/src/main/java/org/vaadin/jchristophe/application/data/Person.java#L19

    /** You can customize your messages here **/
    @Size(min = 3, max = 250, message = "{custom.Size.message}")
    private String lastName;

The error shown in the application in Fusion is: {custom.Size.message} image

Without any message, the message shown is only in English and hardcoded in this typescript class: https://github.com/vaadin/flow/blob/master/flow-client/src/main/resources/META-INF/resources/frontend/form/Validators.ts#L255

The same behavior happens for custom validator: For example:

    @CheckCase(CaseMode.LOWER)
    @Size(min = 3, max = 250)
    private String firstName;

Will be validated on the server side when I call the Endpoint and displays this error:

{org.hibernate.validator.referenceguide.chapter06.CheckCase.message}

Expected behavior

I want to display in my application the message I define in the code. This means:

  • Being able to interpolate all the messages on the client side with my own interpolator.
  • Being able to override all the hardcoded texts in the form package with my own

Actual behavior

Currently I only find bad workarounds:

  • Redefine all my validation on the client side to define my own messages instead of the default English

Versions:

- Vaadin / Flow version: 19 and 20
- Java version: N/A
- OS version: N/A

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Haprogcommented, Jan 3, 2022

The documentation is still to be done (see #159), but here’s an example of how this can be used: https://github.com/Haprog/vaadin-fusion-message-interpolator-example#readme (The custom interpolation logic I have implemented here could be later added as a more higher level API or maybe published as a separate addon/package that you could use to make it easier to declare your localizations with little boilerplate. Take this as a proof of concept for now.)

0reactions
haijian-vaadincommented, Jan 3, 2022

Great. Will it be ready to be tested for Vaadin 22.x or 23?

It’s for 23

Read more comments on GitHub >

github_iconTop Results From Across the Web

[FUSION] Messages from the form validation are not interpolated
I want to display in my application the message I define in the code. This means: Being able to interpolate all the messages...
Read more >
spring validation message does not interpolate - Stack Overflow
I'm trying to understand the validation messages and internationalization mechanism in spring and I wrote the following code:
Read more >
Intro to Vaadin Fusion forms: data binding, validation, custom ...
In this video, Marcus Hellberg explains the basics of using Vaadin Fusion forms by building a simple blogging platform.
Read more >
Chapter 4. Interpolating constraint error messages
Message interpolation is the process of creating error messages for violated Bean Validation constraints. In this chapter you will learn how such messages...
Read more >
Photon Engine: Fusion Introduction
The Photon cloud serves as a package relay and has full access to the network state with no need to run Unity, allowing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found