Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline javascript with thymeleaf escaping character

I use thymeleaf and spring. I try to do inline javascript.

<script th:inline="javascript">

    $("#genericTable").bootstrapTable({
        url: /*[[${url}]]*/ 'generic',
        ...
     });    

On the server side I do

 model.addAttribute("url", "/rest/vehicles");

I get

url: "\/rest\/vehicles",

Why some caracters are added to the string?

Edit

with

url: /*[[@{${url}}]]*/ 'generic',

first / is like removed, so it's invalid to call...

like image 783
robert trudel Avatar asked Sep 14 '25 11:09

robert trudel


1 Answers

[(...)] should help

Example with problem I am facing:

$.getJSON('[[@{/management/users/search/unit/}]]' + value, function(data) {

Is transformed to:

$.getJSON('"\/management\/users\/search\/unit\/"' + value, function(data) {

Using [(...)]:

$.getJSON('[(@{/management/users/search/unit/})]' + value, function(data) {

Is transformed to:

$.getJSON('/management/users/search/unit/' + value, function(data) { 

From Thymeleaf 3.0 docs

Note that, while [[...]] corresponds to th:text (i.e. result will be HTML-escaped), [(...)] corresponds to th:utext and will not perform any HTML-escaping.

like image 67
David Avatar answered Sep 17 '25 07:09

David