Frage

I have a list of strings - which are the properties names that I am interested in: I want to join the values of these strings, but not using the properties name, but the properties values for them. I saw that the starting point is #strings.listJoin - but how can I say to match the elements in the list against their value in the properties files?

The list would be: [name, address] and in the properties file I have:

name=stg
address=another something
I would like to obtain the string: stg, another something

War es hilfreich?

Lösung

You can do it by utilizing #messages.listMsg and #strings.listJoin

Having the model returned from your @Controller:

model.addAttribute("messageKeyList", Lists.newArrayList("name", "address"));

You can join list of translated messages like this:

<div th:text="${#strings.listJoin(#messages.listMsg(messageKeyList), ',')}"></div>

Which should produce what you expect, e.g.:

Some name,Some address

Where name and address are keys in your messages file.

Andere Tipps

In case you are using localization, the #messages.listMsg part will try to translate each string in the list, resulting in what @Oleksii mentioned in his comment above. If you want just to print the strings as-is, use this:

<div th:text="${#strings.listJoin(messageKeyList, ',')}"></div>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top