Conditional Expression (docs):Spring Thymeleaf - Условные выражения в е: поле
<tr th:class="${row.even}? 'even' : 'odd'">
Я хочу использовать условное выражение в го: поле. Но каждый раз, когда я пытаюсь его я получаю следующее сообщение об ошибке:
*only variable expressions ${...} or selection expressions {...} are allowed in Spring field bindings
Например:
// This works fine.
<input type="text" th:value="${object.covered} ? 'yes' : 'no'" />
// This on the other hand, generates the error mentioned earlier.
// Which does make sense, cause it would otherwise generate invalid attributes.
<input type="text" th:field="${object.covered} ? 'yes' : 'no'" />
// Combining the two does not work.
<input type="text" th:field="${object.covered}" th:value="${object.covered} ? 'yes' : 'no'" />
В общем, что я хочу, это создать й: поле, где его значение определяется условным выражением.
Более конкретно, в моей реализации я хочу заполнить поле ввода номером (Java long) из моей модели. И если это число равно нулю или меньше, я хочу вместо этого использовать местозаполнитель.
// Ultimateley, what I want to achieve is something like this.
<input type="text" th:field="${person.age}"
th:value="${person.age} le 0 ? null : ${person.age}"
placeholder="age" />
Как использовать th: field и определить его значение с условным выражением с помощью Spring Thymeleaf?
(Thymeleaf 2.1.5, и весна загрузки 1.4.2)