[FUSION] Messages from the form validation are not interpolated
See original GitHub issueDescription 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}
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:
- Created 2 years ago
- Reactions:6
- Comments:6 (3 by maintainers)
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.)
It’s for 23