Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

Conditional inline formatting with thymeleaf attributes

$
0
0

I want to conditionally style elements by comparing two attributes.

  1. a url parameter 'customerID'

http://localhost:8080/home?customerID=3

  1. a model attribute

th:each=" customer : ${customers}"

I want to change the background of a button if these two parameters are equal. I'm using inline styling with thymeleaf.

th:style="${param.customerID == customer.id ? 'background-color:green' : 'background-color:red'}"

but the result of the condition is always false even when the two arguments are equal.

<div class="user-list">
    <div class="active-btn-group" id="active-button-group" th:each=" customer : ${customers}">

        <p th:text="${param.customerID}">Test</p>
        <p th:text="${customer.id}">Test</p>
        <button th:id="${customer.id}" th:style="${param.customerID == customer.id ? 'background-color:green' : 'background-color:red'}">

        </button>
    </div>
</div>

How should I change the about inline formatting expression?


Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>