Reputation: 113
I am trying to change the background of a div depending of a variable systemStatus
from an object taken from a database.
th:style="${system.systemStatus} == 1} ? 'background: green' : 'background: red'"
But I get the error:
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "${system.systemStatus} == 1} ? 'background: green' : 'background: red'" (template: "system-management" - line 48, col 41)
I've tried to make a function to get systemStatus
as a string:
th:style="${system.systemStatusString()} == '1'} ? 'background: green' : 'background: red'"
but I get the same error.
The whole div:
<div class="form-group" th:style="${system.systemStatus} == 1} ? 'background: green' : 'background: red'">
<label for="id">ID: </label>
<input type="text" th:value="${system.id}" th:name="id" th:id="id" class="form-control" id="id" readonly />
<br>
<label for="machineId">Machine ID: </label>
<input type="text" th:value="${system.machineId}" th:name="machineId" th:id="machineId" class="form-control" id="machineId"/>
</div>
Upvotes: 0
Views: 616
Reputation: 133
You have an extra }
. The actual code should be like
th:style="${system.systemStatus} == 1 ? 'background: green' : 'background: red'"
Upvotes: 1