Nuñito Calzada
Nuñito Calzada

Reputation: 1688

Thymeleaf: EL1043E: Unexpected token

I have a thymeleaf with this piece of code:

<p th:utext="${#strings.replace( #strings.escapeXml( user.text ),${lineSeparator},'&lt;br /&gt;')}" >
                                Presentación
                            </p>

and in the controller:

model.addAttribute("lineSeparator", System.lineSeparator());

but I have this error when I access the page:

05:38:22.290 [http-nio-7080-exec-8] ERROR org.apache.juli.logging.DirectJDKLog.log 175 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing faile
d; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#strings.replace( #strings.escapeXml( user.text ),${lineSeparator},'<br />')" (temp
late: "user" - line 217, col 11)] with root cause
org.springframework.expression.spel.SpelParseException: Expression [#strings.replace( #strings.escapeXml( user.text ),${lineSeparator},'<br />')] @52: EL1043E: Unexpected token. Expected 'rparen())' but 
was 'lcurly({)'

Upvotes: 0

Views: 2762

Answers (1)

Metroids
Metroids

Reputation: 20487

You can't nest ${...} expressions without doing preprocessing (and in most cases you shouldn't ever need to unless you are doing preprocessing). Remove the ${...} around lineSeparator.

<p th:utext="${#strings.replace(#strings.escapeXml(text), lineSeparator,'&lt;br /&gt;')}" >
  Presentación
</p>

Upvotes: 3

Related Questions