How to remove tag span, space, new line character in Thymeleaf conditional code block?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to remove tag span, space, new line character in Thymeleaf conditional code block?

donhuvy
I am using Spring Boot 2.1.5.RELEASE, Thymeleaf 3.0.11.RELEASE (thymeleaf-3.0.11.RELEASE.jar), Thymeleaf Spring 3.0.11.RELEASE (thymeleaf-spring5-3.0.11.RELEASE.jar)

code snippet

<nabble_embed> <tr th:each="employee : ${employeeList}"> <td th:text="${employee.order}"></td> <td th:text="${employee.age}"></td> <td th:switch="${employee.level}"> <span th:case="0">Junior</span> <span th:case="1">Senior</span> <span th:case="2">Expert</span> </td> <td th:text="${employee.activeStatus}"></td> </tr> </nabble_embed>

For sorting in data-grid by JavaScript, I need remove  tag pairs. For example, if an employee has level = 2. This time, Thymeleaf will render

<nabble_embed> <td><span>Expert<span></td> </nabble_embed>

I hope it become to

<nabble_embed><td>Expert</td></nabble_embed>

(without  tag). How to to this?

I also try


<nabble_embed><tr th:each="employee : ${employeeList}"> <td th:text="${employee.order}"></td> <td th:text="${employee.age}"></td> <td th:switch="${employee.level}"> <th:block th:case="'0'">Junior</th:block> <th:block th:case="'1'">Senior</th:block> <th:block th:case="'2'">Expert</th:block> </td> <td th:text="${employee.activeStatus}"></td> </tr> </nabble_embed>

But It generate unwanted character


<nabble_embed><td> Expert </td></nabble_embed>

(Has new line or space before text, It not wanted result)

https://stackoverflow.com/questions/56506667/how-to-remove-tag-span-space-new-line-character-in-thymeleaf-conditional-code