24

I am using IntelliJ IDEA and I have a problem with thymeleaf namespaces. I have created employee form which I am including into other templates so I did not specified namespaces but it works fine when I run my application. Is there any way to change this behaviour. I like to have an auto-complete :-)

Namespace 'th' is not bound example:

Namespace 'th' is not bound

Purzynski
  • 1,107
  • 2
  • 13
  • 35

5 Answers5

27

Also, if you are using Spring you should use the following:

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
  <head>
     <title>Hello</title>
  </head>
  <body>
  </body>
</html>

The difference is in the DOCTYPE. See Intellij Idea: Thymeleaf namespace unkown

Grigory Kislin
  • 16,647
  • 10
  • 125
  • 197
13

To enable auto completion and IDE support for Thymeleaf, make sure you have enabled the Thymeleaf plugin.

File -> Other Settings -> Config Plugins -> tick Thymeleaf

screenshot of plugin window

Also add the namespace in the root tag

<html .... xmlns:th="http://www.thymeleaf.org">

riddle_me_this
  • 8,575
  • 10
  • 55
  • 80
Faraj Farook
  • 14,385
  • 16
  • 71
  • 97
7

There's no harm defining your fragments in a well formed document (including a html, head, body etc). In fact this is how the Thymeleaf Documentation does it.

This way you can specify the thymeleaf namespace so you get autocomplete, and you can also view your fragments by themselves in the browser, which is useful for prototyping.

Andrew
  • 1,269
  • 7
  • 9
3

Adding xmlns:sec="http://www.thymeleaf.org" into the html tag helped me. So now it looks like below:

<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org"
      lang="en">
<head>
0

If you are using Intellij IDEA, you can also use the JBLHtmlToThymeleaf plugin. With this plugin, you can simply right click on your HTML file and add the required namespace.

Operation steps for this: (on the IDE)

File->Settings->Plugins->Marketplace and search JBLHtmlToThymeleaf

Install JBLHtmlToThymeleaf

After the installation is complete, right click on a desired html file and select JBLHtmlToThymeleaf.

Right click the HTML file

After the process is complete, you will see that the namespace xmlns: th = "http://www.thymeleaf.org" has been added automatically.

Bonus: Also if you want to use Spring Security in HTML file, don't forget to add xmlns: sec = "http://www.thymeleaf.org/extras/spring-security".