Home > other >  Spring Boot message.properties Question: How to send value to the fragment?
Spring Boot message.properties Question: How to send value to the fragment?

Time:01-25

I have a problem about sending the value coming from message.properties file to the thymeleaf fragment page. After I defined the value in message.properites file named as "brand.name" , I'd like to send it to that page but I couldn't handle with it.

Even if I can use column_link('name',[[#{brand.name}]],'none')" or column_link('name',#{brand.name},'none')", I cannot show the name in fragment.

How can I do that?

Here is my message_en.properties file shown below.

...
brand.name = Brand Name:
...

Here is my HTML page shown below.

...
<th th:replace="fragments :: column_link('name','Brand Name','none')" />
...

Here is my fragment page shown below.

<th th:fragment="column_link(fieldName, columnLabel, removeTag)" th:remove="${removeTag}">
    
        <a 
            th:href="@{${moduleURL}   '/page/'   ${currentPage}   '?sortField='   ${fieldName}   '&sortDir='   ${sortField != fieldName ? sortDir : reverseSortDir}   ${keyword != null ? '&keyword='   keyword : ''}">
            [[${columnLabel}]]
        </a>                                
        <span th:if="${sortField == fieldName}"
            th: ></span> 
                            
</th>

CodePudding user response:

You should be able to pass a property in like this:

<th th:replace="fragments :: column_link('name',#{brand.name},'none')" />
  •  Tags:  
  • Related