Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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})}'" >
like image 780
La Carbonell Avatar asked Dec 18 '22 06:12

La Carbonell


1 Answers

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})} + '\''"
like image 151
Metroids Avatar answered Dec 20 '22 20:12

Metroids