JBoss Community

Possible ThymeLeaf Integration

modified by Ondrej Zizka in JBoss AS 7 Development - View the full document

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.

          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.

 

  • 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);

 

 

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

 

Comment by going to Community

Create a new document in JBoss AS 7 Development at Community