Skip to main content

Posts

Showing posts from October, 2019

Rendering template from string using thymeleaf in spring

Finally solved a very big problem for me... How do I render a page in spring framework that uses the thymeleaf templating engine? The string most probably will come from the database. After long hours of searching and trying, I've got it.

First I've got a clue from this particular stackoverflow question. But following an example from there got me an error about class not found for ognl.PropertyAccessor. That solution was found here.

So here's how I finally done it...

First thing is to create a service where that service can be used wherever you need it in your spring app.


@Service public class PortalService { private TemplateEngine templateEngine; private final static String TEMPLATE_LOCAL = "US"; private TemplateEngine getTemplateEngine(){ if(null == templateEngine){ templateEngine = new TemplateEngine(); StringTemplateResolver templateResolver = new StringTemplateResolver(); templateResolver.s…