ThymeLeaf is a templating engine.
Possible integration points
In CDI, even standalone:
@Inject CDIThymeContext ctx;
By default, ThymeLeaf uses OGNL against the map of variables to resolve the expressions.
Therefore, the map provided by CDIThymeContext would probably have to
- list all beans CDI could deliver, limited to those marked as beans somehow (i.e. not "any class"),
- override the methods of VariablesMap which ThymeLeaf actually uses, and look up the beans lazily.
- Unfortunatelly, this wouldn't work:
java.lang.UnsupportedOperationException at cz.oz.thymeleaftry.cdi.LazyVariablesMap.size(LazyVariablesMap.java:27) at java.util.HashMap.putAll(HashMap.java:597) at org.thymeleaf.context.AbstractProcessingContext.createEvaluationRoot(AbstractProcessingContext.java:95)
- Also, we could make the template names type-safe, by introducing one qualifier per page.
// Inject object with the template "Home", the template engine, and CDIThymeContext. @Inject @Template @Home ThymeTemplate tpl; // Additional variables. tpl.getContext().setVariable("foo", bar); // Process. tpl.process( response.getWriter() );
Additionally, in Application Server:
- IResourceResolver - to load resources from deployments. ThymeLeaf's ClassLoaderResourceResolver uses just
- ICacheManager - use InfiniSpan as cache.
- @Resource TemplateEngine templateEngine; - inject template engine configured as module. (Probably not much useful, ThymeLeaf is pretty simple, almost no config.)
- IMessageResolver - anything useful to get the strings from?