I am trying to put border color red if a student is fail by using following expression
<div class="image_wrap" th:style="${student.studentExamStatus}?border-style: solid;border-color: red;:">
but I am getting following exception
Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "${student.studentExamStatus}?border-style: solid;border-color: red;:"
${student.studentExamStatus} will return either 0 or 1 based student passed exam or not.
Adding CSS. We load the stylesheet using the link tag with Thymeleaf's special th:href attribute. If we've used the expected directory structure, we only need to specify the path below src/main/resources/static. In this case, that's /styles/cssandjs/main.
An inline style may be used to apply a unique style for a single element. To use inline styles, add the style attribute to the relevant element. The style attribute can contain any CSS property.
The one way to add CSS and JS files is to add them to the static folder of src/main/resources and reference it to the Thymeleaf template. Here @{} is the way of linking URL in Thymeleaf.
As @Andrew said, you need to need to nest your style statements in single quotes. And you must include your expression inside the brackets :
<div class="image_wrap" th:style="${student.studentExamStatus ? 'border-style: solid;border-color: red;' : ''}">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With