Not able to use String function using Spring Context

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

Not able to use String function using Spring Context

dkdarshu45@gmail.com
This post was updated on .
I am using Spring , and have set below via code :
 
 Context context = new Context();
        context.setVariable("name", "Spring");
        context.setVariable("url", "http://spring.io");
        context.setVariable("mtcn", "123456789ABCDEF");



template :


Name: [(${name})]
Link: [(${url})]
MTCN: [${#strings.length(name)}]



The name and link works ,but string function is not returning correct value ,it is returning :

Name: Spring
Link: http://spring.io
MTCN: [${#Strings.length(name)}]
Reply | Threaded
Open this post in threaded view
|

Re: Not able to using String function

dkdarshu45@gmail.com
Tried using :

[${#strings.length(name)}]

This also doesnt work
Reply | Threaded
Open this post in threaded view
|

Re: Not able to using String function

Zemi
Administrator
I don't have a running app with TEXT mode here but your expression must be inside [( ... )] so you should try something like [(${#strings.length(name)})]
Reply | Threaded
Open this post in threaded view
|

Re: Not able to using String function

dkdarshu45@gmail.com
This post was updated on .
Getting this exception :



 An error happened during template parsing (template: "templates/text/text-template_bkp.txt")] with root cause

java.lang.RuntimeException: MemberAccess implementation must be provided!


        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]
Caused by: org.thymeleaf.templateparser.text.TextParseException: Exception evaluating OGNL expression: "#strings.length(url)" (template: "text-template_bkp" - line 7, col 10)



Can you help with this ?
Reply | Threaded
Open this post in threaded view
|

Re: Not able to using String function

dkdarshu45@gmail.com
Using SpringTemplateEngine instead of templateEngine resolved the issue