La Carbonell
La Carbonell

Reputation: 2056

window.location.href on thymeleaf

I have this piece of code in my Thymeleaf template but it does not work properly since this is the location generated

deviceevent/@%7B/deviceevent/list/%7Bid%7D(id=$%7BdeviceEvent.id%7D)%7D

in the template

<tr th:each="deviceEvent : ${deviceEvents}"  onclick="window.location.href = '@{/deviceevent/list/{id}(id=${deviceEvent.id})}'" >

Upvotes: 4

Views: 13972

Answers (1)

Metroids
Metroids

Reputation: 20477

Thymeleaf doesn't evaluate attributes unless they are prefixed with th. In this case, th:onclick. The complete string should look like this:

th:onclick="'window.location.href = \'' + @{/deviceevent/list/{id}(id=${deviceEvent.id})} + '\''"

Upvotes: 11

Related Questions