1

I'm using Thymeleaf 3.0.11 with Spring 4.3.22, no Boot. Have this code:

<tbody class="clientdata section" th:data-id="${formModel?.client?.person?.userId ?: ''}">

It works fine when the userId has a value. Then the output is, for example:

<tbody class="clientdata section" data-id="178051">

However, when the userId is null, the attribute disappears altogether:

<tbody class="clientdata section">

If i specify some dummy value in case of null userId, it works fine:

<tbody class="clientdata section" th:data-id="${formModel?.client?.person?.userId ?: '0'}">

But why not just render attribute with empty value? I.e. i would like it to render:

<tbody class="clientdata section" data-id="">

in case the userId is null.

k6ps
  • 359
  • 4
  • 11
  • 1
    Not possible in Thymeleaf, as far as I know. – Metroids Feb 28 '20 at 16:48
  • I did not find any way either. Finally i took the dummy value approach, and adjusted the JavaScript that uses the ```data-id``` attribute. – k6ps Mar 02 '20 at 11:58

0 Answers0