7

I want to add google map javascript to a Thymeleaf template, like this:

https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places

It throws the exception:

org.xml.sax.SAXParseException; lineNumber: 209; columnNumber: 93; The reference to entity "key" must end with the ';' delimiter

I tried to change & to & but nothing changed.

Your help will be greatly appreciated. Thanks!

riddle_me_this
  • 8,575
  • 10
  • 55
  • 80

3 Answers3

6

Thymeleaf uses XML parser, and the character & is considered a special character in XML. You have to replace & with its XML equvilant &.Your URL will be:

https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places

In thymeleaf 3, it won't be a problem since they wrote a new parser for thymeleaf.

Aboodz
  • 1,549
  • 12
  • 23
0

It was a bug in Thymeleaf but it was fixed since 2.1.4.

Look at this issue. (The trouble described in this question).

Community
  • 1
  • 1
sanluck
  • 1,544
  • 1
  • 12
  • 22
0

You have some options:

1) Don't use the th:src at all.

2) Since the URL is absolute, you can add it server-side using a static method:

<script th:src="${@urlService.getMapsUrl()}">...</script> 

3) Use a rewrite filter.

Not sure whether the issue is corrected in Thymeleaf 3, but it could be worth upgrading quickly and taking a look.

Community
  • 1
  • 1
riddle_me_this
  • 8,575
  • 10
  • 55
  • 80