Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to process and join string in thymeleaf

Tags:

java

thymeleaf

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
like image 361
Roxana Avatar asked Apr 09 '14 10:04

Roxana


1 Answers

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.

like image 143
Rafal Borowiec Avatar answered Oct 21 '22 11:10

Rafal Borowiec