Thymeleaf: Concatenation - Could not parse as expression -


i'm having issue when trying concat multiple values in template. according thymeleaf here should able + them together...

4.6 concatenating texts

texts, no matter whether literals or result of evaluating variable or message expressions, can concatenated using + operator:

th:text="'the name of user ' + ${user.name}" 

here example of found works:

<p th:text="${bean.field} + '!'">static content</p> 

this doesn't:

<p th:text="${bean.field} + '!' + ${bean.field}">static content</p> 

logically, should work not, doing wrong?


maven:

<dependency>     <groupid>org.thymeleaf</groupid>     <artifactid>thymeleaf-spring3</artifactid>     <version>2.0.16</version>     <scope>compile</scope> </dependency> 

here how i've set templateengine , templateresolver up:

<!-- spring config --> <bean id="templateresolver" class="org.thymeleaf.templateresolver.classloadertemplateresolver">     <property name="suffix" value=".html"/>     <property name="templatemode" value="html5"/>     <property name="characterencoding" value="utf-8"/>     <property name="order" value="1"/> </bean> <bean id="templateengine" class="org.thymeleaf.spring3.springtemplateengine">     <property name="templateresolver" ref="filetemplateresolver"/>     <property name="templateresolvers">         <list>             <ref bean="templateresolver"/>         </list>     </property> 

thymeleaftemplatingservice:

@autowired private templateengine templateengine; ..... string responsetext = this.templateengine.process(templatebean.gettemplatename(), templatebean.getcontext()); 

abstracttemplate.java:

public abstract class abstracttemplate {   private final string templatename;   public abstracttemplate(string templatename){     this.templatename=templatename;   }   public string gettemplatename() {     return templatename;   }   protected abstract hashmap<string, ?> getvariables();   public context getcontext(){     context context = new context();     for(entry<string, ?> entry : getvariables().entryset()){       context.setvariable(entry.getkey(), entry.getvalue());     }     return context;   } } 

but see have quite simple error in syntax

<p th:text="${bean.field} + '!' + ${bean.field}">static content</p> 

the correct syntax

<p th:text="${bean.field + '!' + bean.field}">static content</p> 

as matter of fact, syntax th:text="'static part' + ${bean.field}" equal th:text="${'static part' + bean.field}".

try out. though kind of useless after 6 months.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -