[jboss-dev-forums] [JBoss AS 7 Development] - Possible ThymeLeaf Integration
Ondrej Zizka
do-not-reply at jboss.com
Mon Dec 10 01:17:07 EST 2012
Ondrej Zizka [https://community.jboss.org/people/ozizka] modified the document:
"Possible ThymeLeaf Integration"
To view the document, visit: https://community.jboss.org/docs/DOC-48038
--------------------------------------------------------------
ThymeLeaf is a templating engine.
http://www.thymeleaf.org/documentation.html http://www.thymeleaf.org/documentation.html
h2. Possible integration points
h4. In CDI, even standalone:
* http://www.thymeleaf.org/apidocs/thymeleaf/2.0.14/org/thymeleaf/context/IContext.html 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 *http://127.0.0.1:8082/resource/jar%3Afile%3A/home/ondra/.m2/repository/org/thymeleaf/thymeleaf/2.0.14/thymeleaf-2.0.14-javadoc.jar%21/org/thymeleaf/context/IContext.html#getVariables%28%29 getVariables*(), so the values are not resolved per case - whole map needs to be given at the time of this call. https://github.com/thymeleaf/thymeleaf/issues/101 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() );
h4. Additionally, in Application Server:
* http://www.thymeleaf.org/apidocs/thymeleaf/2.0.14/org/thymeleaf/resourceresolver/IResourceResolver.html IResourceResolver - to load resources from deployments. ThymeLeaf's ClassLoaderResourceResolver uses just
ClassLoaderUtils.getClassLoader(ClassLoaderResourceResolver.class).getResourceAsStream(resourceName);
* http://www.thymeleaf.org/apidocs/thymeleaf/2.0.14/org/thymeleaf/cache/ICacheManager.html 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.)
* http://www.thymeleaf.org/apidocs/thymeleaf/2.0.14/org/thymeleaf/messageresolver/IMessageResolver.html IMessageResolver - anything useful to get the strings from?
--------------------------------------------------------------
Comment by going to Community
[https://community.jboss.org/docs/DOC-48038]
Create a new document in JBoss AS 7 Development at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2225]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20121210/2e9ce5c4/attachment.html
More information about the jboss-dev-forums
mailing list