Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error parsing thymeleaf template with "1 < 0"

Tags:

thymeleaf

Maybe is a stupid question but I failed to retrieve information from Google. As the title say, I get a stack trace if a try to parse this simple line:

<span th:if="${1 < 0}">

The error is:

org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 43; The value of attribute "th:if" associated with an element type "null" must not contain the '<' character.

But if i try this:

<span th:if="${0 > 1}">

Everything is fine, my question is: Why I get this error?

I believe is related to my lack of experience with Java and thymeleaf, but I don't get why by just changing the position of the elements it work as I expect (return always false).

It is a bug in the parsing of the expression (as checking if 1 is lower than 0 is forbidden by some parser rule) or is just a weird XML parsing issue?

Thank you to all who will even just read.

like image 623
Matteo Avatar asked May 03 '13 13:05

Matteo


2 Answers

You have to escape the symbol by using

&lt; for < 
&gt; for >
&le; for <= 
&ge; for >=

So your code should look like :

<span th:if="${1 &lt; 0}">

You can find the whole doc about this in the 'Using Thymeleaf' tutorial on their website, in the comparators-and-equality section.

like image 167
brnrd Avatar answered Dec 27 '22 13:12

brnrd


&le; for <= 
&ge; for >=

didn't work for me. I had to use:

&lt;= for <= 
&gt;= for >=

It seems that &le; and &ge; are not accepted as well-formed XML.

This solves the "IllegalStateException: Cannot handle (8804) '≤' " problem.

like image 34
Maxime G. Avatar answered Dec 27 '22 13:12

Maxime G.