0
I have an app Spring Boot
where I’m developing a system Web
using Thymeleaf
. The system has the translation functionality according to the language of the user, however, when using in the entity, through the annotations
validations, for example, the @Size
with min
and max
is not passed to the entity. I would like to know what the solution to this problem. I stress that, in the other, the translation works correctly.
Below are more details: Entity:
@Column(name = "corporate_name", length = 255, nullable = false)
@Size(min = 3, max = 255, message = "{entities.messages.size.corporate-name}")
protected String corporateName;
@Column(name = "fantasy_name", nullable = false)
@Size(min = 3, max = 255, message = "{entities.messages.size.fantasy-name}")
protected String fantasyName;
The message in the translation file:
entities.messages.size.corporate-name=The corporate name must be between {0} and {1} characters.
entities.messages.size.Fantasy-name=The Fantasy name must be between {0} and {1} characters.
As far as I had researched and understood on this subject, the minimum and maximum values of the annotation
Size
, should be automatically replaced by the respective values {0}
and {1}
of the message, however, when performing the tests, is displayed 0 and 1 as can be seen below:
It was expected to be displayed, for example, the message:
The corporate name must be between 3 and 255 characters.
Will your message file you do not have to structure as follows:
Size.MinhaEntidade.meuAtributo=Exam title must contain between {2} and {1} characters.
? I looked at that reference: https://dzone.com/articles/exception-handling-and-i18n-on-spring-boots-apis-p– Adriano Gomes
@Fabio Souza, I answered with the same content of the other negative answer, but with links of documentation. After I saw that you commented that it did not work properly! What makes me wonder if it is not some configuration error of your project. I have an API that currently uses {min} and {max} with custom messages and works 100%. Could you kindly describe the class Imports and the project structure where
@Configuration
to load the Undles, and Validator you are using?– nullptr
@nullptr, I found the definition https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/? v=7.0#_examples you are correct there is even this behavior on the part of the annotation
@Size
. The mistake is mine.– Augusto Vasques
Included a project with a working example on my github, I also added unit tests to validate the feedback message.
– nullptr
I still suspect that there is some configuration problem in the @Fabio project
– nullptr