Thymeleaf: clickable row
I had to solve pretty similar problem with Tymeleaf, and I've also been needed to pass request parameter from item to the url, so I solved like this:
<tr th:each="item : ${itmes}" style="cursor: pointer"
th:onclick="'javascript:rowClicked(\'' + ${item.someField} + '\');'">
...
<td>Some data</td>
...
</tr>
then include somehow the script:
<script>
function rowClicked(value) {
location.href = "/myurl?param=" + value;
}
</script>
For the latest thymeleaf version, answer by @Andrew will not work due to the following issue. The code will have to be modified as follows:
<tr th:each="item : ${itmes}" style="cursor: pointer"
th:some-field="${item.someField}" onclick="rowClicked(this.getAttribute('some-field'))">
...
<td>Some data</td>
...
</tr>