Thymeleaf: improving your Spring view layer with natural templates
-
Upload
spring-io -
Category
Technology
-
view
6.158 -
download
9
description
Transcript of Thymeleaf: improving your Spring view layer with natural templates
![Page 1: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/1.jpg)
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.
ThymeleafImproving your Spring View Layer with Natural Templates
Emanuel Rabina - @u1traq
![Page 2: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/2.jpg)
http://www.thymeleaf.org/
@thymeleaf
Thymeleaf
![Page 3: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/3.jpg)
Background
![Page 4: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/4.jpg)
Hello World!<p> </p>
![Page 5: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/5.jpg)
www.alanwood.net/unicode/utilities_editors.html
![Page 6: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/6.jpg)
mozillaquest.com/stories_01/Composer-01/Moz_0_8_Composer01_story_02.html
![Page 7: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/7.jpg)
<b> bold </b>
<i> </i>italic
<blink> </blink>...
![Page 8: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/8.jpg)
![Page 9: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/9.jpg)
Dynamic Web• Perl• JSP• PHP• ASP• GSP• anything-that-ends-with-P
![Page 10: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/10.jpg)
![Page 11: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/11.jpg)
Dynamic Web• Perl• JSP• PHP• ASP• GSP• anything-that-ends-with-P
• JSF• GWT
![Page 12: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/12.jpg)
<h:panelGrid>
...
</h:panelGrid>
![Page 13: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/13.jpg)
The Language Barrier
![Page 14: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/14.jpg)
Client-side languages Server-side languages
HTML
CSS
JavaScript
Java
C#Ruby
PerlGroovy
Scala
?
![Page 15: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/15.jpg)
sans-pants.com/2010/04/27/great-pants-imagery/
![Page 16: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/16.jpg)
HTML
PHP
JSP
ASP.NET
Ruby on Rails
GSP
CGI
ScalaTemplates
CFM
![Page 17: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/17.jpg)
www.flickr.com/photos/wgtncc/6834607270/
![Page 18: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/18.jpg)
Enter Thymeleaf
![Page 19: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/19.jpg)
Natural Templates
“The template can be a document as valid as the final result, the engine syntax doesn’t break the document structure.”
en.wikipedia.org/wiki/Comparison_of_web_template_engines
![Page 20: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/20.jpg)
Natural Templates
![Page 21: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/21.jpg)
(JSP example)
![Page 22: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/22.jpg)
![Page 23: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/23.jpg)
(Thymeleaf example)
![Page 24: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/24.jpg)
Natural Templates
JSP opened w/ browser Thymeleaf opened w/ browser
![Page 25: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/25.jpg)
<% ... %>
<?php ... ?>
<%= ... %>
<g:each...>
<c:forEach...>
@for <cfloop...>
<ui:repeat...>
#foreach
![Page 26: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/26.jpg)
th:attr
th:attrappend
th:attrprepend
th:case
th:classappend
th:each
th:fragment
th:object
th:if
th:inline
th:unless
th:include
![Page 27: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/27.jpg)
Natural Templates• Quick prototyping• Design in the browser• Encouraged to add text and content• No need to start an app server• It’s HTML
![Page 28: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/28.jpg)
Extending Thymeleaf
![Page 29: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/29.jpg)
Dialects• Prefix• Processors• Expression objects
theach, text, utext, ...#dates, #arrays, ...
![Page 30: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/30.jpg)
public class MyDialect extends AbstractDialect implements IExpressionEnhancingDialect {
public Map<String,Object> getAdditionalExpressionObjects(...);
public String getPrefix();
public Set<IProcessor> getProcessors();
}
![Page 31: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/31.jpg)
public class MyProcessor extends AbstractAttrProcessor {
public MyProcessor(); // Constructor
public int getPrecedence();
public ProcessorResult processAttribute( Arguments arguments, Element element, String attributeName);
}
![Page 32: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/32.jpg)
(Custom dialect example)
![Page 33: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/33.jpg)
Working with Spring
![Page 34: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/34.jpg)
![Page 35: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/35.jpg)
(Spring example)
![Page 36: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/36.jpg)
Ecosystem
![Page 37: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/37.jpg)
Early 2012
![Page 38: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/38.jpg)
Extras / ‘official’
•Conditional CommentsProcessing of all the kinds of Internet Explorer conditional comments
•Spring Security 3Adds attribute processors and utility objects to use Spring Security expressions
•Tiles 2Use Apache Tiles 2 to compose your templates
•Eclipse PluginContent assist (autocomplete/suggestions) support in Eclipse
![Page 39: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/39.jpg)
Community
•ThymolIncludes other pages referenced with th:include when viewed statically
http://sourceforge.net/u/jjbenson/wiki/thymol/
•Dandelion DataTables
http://dandelion.github.io/datatables
Ridiculously customizable tables for the display of data
•Layout Dialect
http://github.com/ultraq/thymeleaf-layout-dialect
Inheritance-based page creation, like SiteMesh or JSF + Facelets
![Page 40: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/40.jpg)
Community
And many more:•modules for the Play Framework•a JRebel plugin option to not cache in development mode•integration with Apache Shiro•client-side form validation using your JSR-303 Bean Validation annotations•runtime optimization of JS/CSS resources•creation of arbitrary data-* attributes•Thymeleaf + Spring MVC Maven archetype•...
![Page 41: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/41.jpg)
Who’s using Thymeleaf?
http://scienceblogs.com/thoughtfulanimal/2010/05/24/dog-personalities/
![Page 42: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/42.jpg)
http://www.broadleafcommerce.com/
![Page 43: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/43.jpg)
http://www.onegini.com/
![Page 44: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/44.jpg)
http://www.ppi.de/
![Page 45: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/45.jpg)
http://www.sahibinden.com/
![Page 46: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/46.jpg)
http://www.trabesoluciones.com/
![Page 47: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/47.jpg)
http://www.yobidrive.com/
![Page 48: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/48.jpg)
How companies have used Thymeleaf• Migrate from other technologies• Take advantage of a Spring-integrated technology (thus making
use of the Spring developer community)• Improve workflow / communication• Allow front-end specialists to really hack the view
![Page 49: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/49.jpg)
The future of Thymeleaf
? ? ?
![Page 50: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/50.jpg)
Future plans• Attoparser• data-* attribute processors• Template fragments as variables• Template-only comments! :)• ‘TEXT’ template mode• Spring/Global formatters• De-coupling processing instructions from templates
![Page 51: Thymeleaf: improving your Spring view layer with natural templates](https://reader034.fdocuments.net/reader034/viewer/2022052303/546d2542af795980298b522f/html5/thumbnails/51.jpg)
Visit our website: http://www.thymeleaf.org/Follow us on Twitter: @thymeleaf
Talk to us on Twitter: @springcentralFind session replays on YouTube: spring.io/video
Learn More. Stay Connected.