How to check classtype of a table field in thymeleaf?

155
June 12, 2019, at 3:50 PM

I have a generic thymeleaf table as follows:

 <tbody>
        <th:block th:each="row : ${page.getContent()}">
            <tr>
                 <td th:each="header : ${headers}" th:text="${row.__${header}__}"/>
            </tr>
        </th:block>
    </tbody>

The table is simply backed by a list containing my domain objects:

List<Header> headers = List.of("firstname", "lastname");
List<Person> page;

What it does is: it loops my predefined list headers, and selects only those attributes defined in the headers list.

Question: how could I add an evaluation on the classtype of the extracted value of each field, so that I could apply a custom style in case of digits?

The problem is: when I output the class of the value that is shown, the output is a java.util.ArrayList always!

th:text="${{row.__${header}__}.class.name}"

Why doesn't this show the correct class of the td element?

Answer 1

Solution as follows to apply a specific css style based on instance check:

 th:text="${row.__${header}__}"
 th:style="${{row.__${header}__}.get(0) instanceof T(java.math.BigDecimal)} ? 'text-align:right' : ''"/>
READ ALSO
Alternative libraries for JAXB and JAX RS (other than reference implementations) while running on jdk 11

Alternative libraries for JAXB and JAX RS (other than reference implementations) while running on jdk 11

Since these two packages have been removed in jdk 11Could you suggest alternate libraries that's compatible with jdk11

144
Hibernate doesn&#39;t insert record to database

Hibernate doesn't insert record to database

I try to add a record to the databaseIn debug, I check to create object and object created is good

179
Find ROM Size Programatically

Find ROM Size Programatically

I am trying to create a test application for a device which checks the flash ROM size on the device for the tester to verify

172
Is it possible to identify what&#39;s the nearest street on google maps?

Is it possible to identify what's the nearest street on google maps?

Is there a way to know the nearest street without using the Directions API of google? Like Uber and 99 does

128