ThymeLeaf is a templating engine.
http://www.thymeleaf.org/documentation.html
Possible integration points
In CDI, even standalone:
- IContext - the map of values available for the template. Those could be filled from CDI.
@Inject CDIThymeContext ctx;
By default, ThymeLeaf uses OGNL against the map of variables to resolve the expressions.
The interface IContext has only getVariables()
, so the values are not resolved per case - whole map needs to be given at the time of this call. RFE
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
ClassLoaderUtils.getClassLoader(ClassLoaderResourceResolver.class).getResourceAsStream(resourceName);
- 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?
Comments