I'm trying to use the value obtained by using model.addattribute() in the controller for th:onclick, but I get an error.
// work correctly
th:onclick="|location.href='/announcement/' + ${list.id}|"
// error occurs
th:onclick="|location.href='/' + ${list.boardCategory} + '/' + ${list.id}|"
"only variable expressions returning numbers or booleans are allowed in this context, any other datatypes are not trusted in the context of this expression, including strings or any other object that could be rendered as a text literal. a typical case is html attributes for event handlers (e.g. "onload"), in which textual data from variables should better be output to "data-*" attributes and then read from the event handler."
The error message is as above.
I'm curious what the problem is and how to solve it. thank you.
I haven't tried it but apparently this should work:
th:onclick="|location.href='/__${list.boardCategory}__/__${list.id}__'|"
apparently you have to evaluate the variable in advance by enclosing it with two underscores.
This should also remove the need to use the + operand