Version 11

    ThymeLeaf is a templating engine.


    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(
              at java.util.HashMap.putAll(
              at org.thymeleaf.context.AbstractProcessingContext.createEvaluationRoot(


    • 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



    • @Resource TemplateEngine templateEngine;   - inject template engine configured as module. (Probably not much useful, ThymeLeaf is pretty simple, almost no config.)