Manually resolve a message to set in a variable

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Manually resolve a message to set in a variable

Dirk Bielemeier
Hello guys!

I want to load messages before a template gets rendered. We have an INFO-Block in the template that will display various messages dependend on the current workflow. What we want to do is to display the Info-Text using a variable, like th:text="${data.infoText}". In the controller we would like to fill the variable "infoText" with a text from one of the message property files. Our property-file looks similar to this:

label.infoText1=Info Text 1
label.infoText2=Info Text 2
label.infoText3=Info Text 3

and so on. Because of the complex decision process which info text to display we want to select the right message using code inside the controller, not inside the template itself using a th:switch, th:case or something equal.

Using the IMessageResolver-Interface, we have a method called "resolveMessage". But this call needs an instance of class "Arguments" that itself consists of an instance of the TemplateEngine-class among others. How can we manually create an Arguments-Instance and provide it with the right settings to resolve a message? Or is there another possibility to resolve a message manually?

Thank you for any help in advance,

Many Regards

Dirk
Reply | Threaded
Open this post in threaded view
|

Re: Manually resolve a message to set in a variable

Zemi
Administrator
Hello,

I'm not sure if I understand your problem, but maybe you want to pass your variable to the i18n processor like in:

   <div th:text="#{${data.infoText}}">Whatever</div>

Reply | Threaded
Open this post in threaded view
|

Re: Manually resolve a message to set in a variable

danielfernandez
Administrator
In reply to this post by Dirk Bielemeier
Are you using Spring? If you are, you can directly @Autowire your MessageSource instance (the one you are using at your Spring infrastructure), because that will be the mechanism on which thymeleaf will be effectively delegating...