`TemplateProcessingException` error with preprocessing expression

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

`TemplateProcessingException` error with preprocessing expression

This post was updated on .
Dear All,
I've come to a preprocessing parsing error.
Given a context attribute with value something like this
"91012_L", "236638002_7 1/2 Large", "128052012_7 (US 37.5) Med"

for example:

  model.addAttribute("value1", "91012_L");
  model.addAttribute("value2", "236638002_7 1/2 Large");
  model.addAttribute("value3", "128052012_7 (US 37.5) Med");

and a `th:href` expression like

    <a th:href="@{offer/__${value1}__}">Value1</a>
    <a th:href="@{offer/__${value2}__}">Value2</a>
    <a th:href="@{offer/__${value2}__}">Value3</a>

then it will throw `org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: ${offer/__${value1}__}`

but when using concatenation (+) symbol then the it works, I don't know why its creating such these problem in preprocessor string expression

    <a th:href="@{'offer/'+${value1}}">Value1</a>
    <a th:href="@{'offer/'+${value2}}">Value2</a>
    <a th:href="@{'offer/'+${value2}}">Value3</a>
Can anyone tell me whats wrong with the values in preprocessor expression case which doesn't parse the expression.

Reply | Threaded
Open this post in threaded view

Re: `TemplateProcessingException` error with preprocessing expression

Your "@{offer/__${value1}__}" is a valid link expression and should be working for you. But your exception message does not say "@{offer/__${value1}__}", but "${offer/__${value1}__}" which is not a link expression but an OGNL/SpringEL one (depending on whether you are using Spring or not). Please, check that you are using link expressions (@{...}) for your links.

By the way, since 2.1 I would recommend not using preprocessing for this, and use literal substitutions (|...|) instead: "@{|offer/${value1}|}"