SlideShare une entreprise Scribd logo
1  sur  23
Spring Teplates
Thymeleaf & Spring framework
History
Servlets
Hello!
public class HelloWorldServlet extends HttpServlet {
protected void doGet(request, response) {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>"); out.println("<head>");
out.println("<title>Hello!</title>");
out.println("</head>");
out.println("<body bgcolor="white">");
out.println("</body>");
out.println("</html>");
}
}
Html symbols are writing directly to the browser from java code.
Servlets
Hello!
public class HelloWorldServlet extends HttpServlet {
protected void doGet(request, response) {
request.getRequestDispatcher("/login.jsp").
forward(request, response);
}
}
Html code saved separately from java code
and can be dynamically changed before sending to browser . It’s good.
<html>
<head>
<title>Hello!</title>
</head>
<body bgcolor=“gray">
<h1>Hello!</h1>
</body>");
</html>
Java Servlet-JSP Architecture
Server Hello World!
Java
Jasper
JSPs
Servlet
container
Templates
Template – document or parts of
document with basic configuration.
Table
with dynamic
content
Left
menu
Spam
Header
Footer
Spring templates.
Apache Velocity
FreeMarker
Rythm
Thymeleaf
 3.8 seconds
 4.8 seconds
 3 seconds
 43.2 seconds
Results obtained after testing with benchmarking tool
for 10000 requests.
Thymeleaf.
Thymeleaf integration with Spring framework.
Custom properties
 Core is a DOM processing engine.
 It is based on XML tags and attributes.
 XML/Valid XML/XHTML/Valid XHTML/HTML5/Legacy
HTML5 processor.
 Allows a fast processing of templates by intelligent caching
of parsed files.
 Not complex syntax.
Syntax compare
FreeMarker syntax:
<table>
<#list animals as animal>
<#if animals.python.price != 0>
<tr>
<td>${animal.name}<td>${animal.price}
</tr>
</#if>
</#list>
</table>
ApacheVelocity syntax:
<table>
#foreach($mud in $mudsOnSpecial)
#if($customer.hasPurchased($mud))
<tr>
<td>$flogger.getPromo($mud)</td>
</tr>
#end
#end
</table>
Syntax compare
Thymeleaf syntax:
<table>
<tr>
<th>NAME</th>
<th>PRICE</th>
<th>IN STOCK</th>
</tr>
<tr th:each="prod : ${prods}">
<td th:text="${prod.name}">Onions</td>
<td th:text="${prod.price}">2.41</td>
<td th:text="${prod.inStock}? #{true} : #{false}">yes</td>
</tr>
</table>
Integration with Spring framework
Spring application context:
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
</bean>
<bean id="templateEngine"
class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
</bean>
Html file template:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
Standard dialect
Expressions:
 Variable Expressions: ${...}
 Selection Variable Expressions: *{...}
 Message Expressions: #{...}
 Link URL Expressions: @{...}
 If-then: (if) ? (then)
 If-then-else: (if) ? (then) : (else)
 Default: (value) ?: (defaultvalue)
Using with basic objects:
 #ctx : the context object.
 #vars: the context variables.
 #locale : the context locale.
 #httpServletRequest : (only in Web Contexts) the
HttpServletRequest object.
 #httpSession : (only in Web Contexts) the
HttpSession object.
Expression Utility Objects:
 #dates : utility methods for java.util.Date objects: formatting, component extraction, etc.
 #calendars : analogous to #dates , but for java.util.Calendar objects.
 #numbers : utility methods for formatting numeric objects.
 #strings : utility methods for String objects: contains, startsWith, prepending/appending, etc.
 #objects : utility methods for objects in general.
 #bools : utility methods for boolean evaluation.
 #arrays : utility methods for arrays.
 #lists : utility methods for lists.
 #sets : utility methods for sets.
 #maps : utility methods for maps.
 #aggregates : utility methods for creating aggregates on arrays or collections.
 #messages : utility methods for obtaining externalized messages inside variables expressions, in the
same way as they would be obtained using #{…} syntax.
 #ids : utility methods for dealing with id attributes that might be repeated.
Dialect extension:
<bean id="templateEngine"
class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
<property name="additionalDialects">
<set>
<bean class="org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect"/>
</set>
</property>
</bean>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:sec=“http://www.thymeleaf.org/thymeleaf-extras-springsecurity4”
xmlns:th="http://www.thymeleaf.org">
Messages internationalization
Application context:
<bean id="messageSource“
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value=“classpath:messages" />
</bean>
Class path:
Fragmentation
footer.html
...
<div th:fragment=“ftr">
Footer
</div>
<div id=“copyrights">
copyrights
</div>
...
Index.html
<body>
...
<div th:include="footer :: ftr"></div>
<div th:include="footer :: #copyrights"></div>
</body>
<div th:fragment="frag (onevar,twovar)">
<p th:text="${onevar} + ' - ' + ${twovar}">...</p>
</div>
<div th:include="::frag (onevar=${value1},twovar=${value2})">
Usage Examples
Object expression:
Today is: <span th:text="${#calendars.format(today,'dd MMMM yyyy')}">11 March
2016</span>
Links usage:
<a href="details.html" th:href="@{/order/details(orderId=${o.id})}">view</a>
<a th:href="@{'/details/'+${user.login}(orderId=${o.id})}">view</a>
Conditions usage:
<div th:if="${user.isAdmin()} == false"> ...-
<div th:if="${user.isAdmin() == false}> ... - Spring EL
<tr th:class="${row.even}? 'class-name'"> ...
<tr th:class="${1 > 0}? 'Yes' : 'No'"> ...
Default expression:
<span th:text=“${value}?: 'no value specified'">Some value</span>
Setting attribute:
<input type="submit" value="Subscribe me!" th:attr="value=#{subscribe.submit}"/>
Forms:
<form action="subscribe.html" th:action="@{/subscribe}">
Iteration:
<tr th:each="item : ${list}">
<td th:text="${item.name}">Onions</td>
<td th:text="${item.count}">2.41</td>
</tr>
Local variable:
<div th:with="firstPer=${persons[0]},secondPer=${persons[1]}">
<span th:text="${secondPer.name}">Some Name</span>.
</div>
Set values to JavaScript:
<script th:inline="javascript">
/*<![CDATA[*/
...
var username = /*[[${session.user.name}]]*/ ‘User';
...
/*]]>*/
</script>
Switch:
<div th:switch="${user.role}">
<p th:case="'admin'">User is an administrator</p>
<p th:case="#{roles.manager}">User is a manager</p>
</div>
Summary
Advatages:
 Java template engine for XML, XHTML and HTML5.
 Works both in web and non-web (offline) environments. No hard dependency
on the Servlet API.
 Several template modes: XML, XHTML 1.0 and 1.1, HTML5:
 Internationalization support.
 Parsed template cache
 Is extensible
 Not very complex in usage
 Many documentation
Disadvatages:
 It's slowly than other templates.
The End.

Contenu connexe

Similaire à 68837.ppt

Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceMaarten Balliauw
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVCRichard Paul
 
A mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesA mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesJames Pearce
 
03 form-data
03 form-data03 form-data
03 form-datasnopteck
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 
Local data storage for mobile apps
Local data storage for mobile appsLocal data storage for mobile apps
Local data storage for mobile appsIvano Malavolta
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actionsAren Zomorodian
 
Java Technology
Java TechnologyJava Technology
Java Technologyifnu bima
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011Arun Gupta
 
05 status-codes
05 status-codes05 status-codes
05 status-codessnopteck
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2Jim Driscoll
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Hugo Hamon
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node jsfakedarren
 
Local storage in Web apps
Local storage in Web appsLocal storage in Web apps
Local storage in Web appsIvano Malavolta
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleKaty Slemon
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAERon Reiter
 

Similaire à 68837.ppt (20)

Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to Space
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
A mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesA mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutes
 
03 form-data
03 form-data03 form-data
03 form-data
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
jQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusionjQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusion
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
Local data storage for mobile apps
Local data storage for mobile appsLocal data storage for mobile apps
Local data storage for mobile apps
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
 
Java Technology
Java TechnologyJava Technology
Java Technology
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011
 
05 status-codes
05 status-codes05 status-codes
05 status-codes
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Broadleaf Presents Thymeleaf
Broadleaf Presents ThymeleafBroadleaf Presents Thymeleaf
Broadleaf Presents Thymeleaf
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Local storage in Web apps
Local storage in Web appsLocal storage in Web apps
Local storage in Web apps
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
 

Plus de BruceLee275640

introductiontogitandgithub-120702044048-phpapp01.pdf
introductiontogitandgithub-120702044048-phpapp01.pdfintroductiontogitandgithub-120702044048-phpapp01.pdf
introductiontogitandgithub-120702044048-phpapp01.pdfBruceLee275640
 
fdocuments.in_introduction-to-ibatis.ppt
fdocuments.in_introduction-to-ibatis.pptfdocuments.in_introduction-to-ibatis.ppt
fdocuments.in_introduction-to-ibatis.pptBruceLee275640
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfBruceLee275640
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxBruceLee275640
 

Plus de BruceLee275640 (7)

Git_new.pptx
Git_new.pptxGit_new.pptx
Git_new.pptx
 
introductiontogitandgithub-120702044048-phpapp01.pdf
introductiontogitandgithub-120702044048-phpapp01.pdfintroductiontogitandgithub-120702044048-phpapp01.pdf
introductiontogitandgithub-120702044048-phpapp01.pdf
 
fdocuments.in_introduction-to-ibatis.ppt
fdocuments.in_introduction-to-ibatis.pptfdocuments.in_introduction-to-ibatis.ppt
fdocuments.in_introduction-to-ibatis.ppt
 
Utility.ppt
Utility.pptUtility.ppt
Utility.ppt
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
 
life science.pptx
life science.pptxlife science.pptx
life science.pptx
 

Dernier

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Dernier (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

68837.ppt

  • 1. Spring Teplates Thymeleaf & Spring framework
  • 3. Servlets Hello! public class HelloWorldServlet extends HttpServlet { protected void doGet(request, response) { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Hello!</title>"); out.println("</head>"); out.println("<body bgcolor="white">"); out.println("</body>"); out.println("</html>"); } } Html symbols are writing directly to the browser from java code.
  • 4. Servlets Hello! public class HelloWorldServlet extends HttpServlet { protected void doGet(request, response) { request.getRequestDispatcher("/login.jsp"). forward(request, response); } } Html code saved separately from java code and can be dynamically changed before sending to browser . It’s good. <html> <head> <title>Hello!</title> </head> <body bgcolor=“gray"> <h1>Hello!</h1> </body>"); </html>
  • 5. Java Servlet-JSP Architecture Server Hello World! Java Jasper JSPs Servlet container
  • 7. Template – document or parts of document with basic configuration. Table with dynamic content Left menu Spam Header Footer
  • 8. Spring templates. Apache Velocity FreeMarker Rythm Thymeleaf  3.8 seconds  4.8 seconds  3 seconds  43.2 seconds Results obtained after testing with benchmarking tool for 10000 requests.
  • 10. Custom properties  Core is a DOM processing engine.  It is based on XML tags and attributes.  XML/Valid XML/XHTML/Valid XHTML/HTML5/Legacy HTML5 processor.  Allows a fast processing of templates by intelligent caching of parsed files.  Not complex syntax.
  • 11. Syntax compare FreeMarker syntax: <table> <#list animals as animal> <#if animals.python.price != 0> <tr> <td>${animal.name}<td>${animal.price} </tr> </#if> </#list> </table> ApacheVelocity syntax: <table> #foreach($mud in $mudsOnSpecial) #if($customer.hasPurchased($mud)) <tr> <td>$flogger.getPromo($mud)</td> </tr> #end #end </table>
  • 12. Syntax compare Thymeleaf syntax: <table> <tr> <th>NAME</th> <th>PRICE</th> <th>IN STOCK</th> </tr> <tr th:each="prod : ${prods}"> <td th:text="${prod.name}">Onions</td> <td th:text="${prod.price}">2.41</td> <td th:text="${prod.inStock}? #{true} : #{false}">yes</td> </tr> </table>
  • 13. Integration with Spring framework Spring application context: <bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"> <property name="prefix" value="/WEB-INF/templates/" /> <property name="suffix" value=".html" /> <property name="templateMode" value="HTML5" /> </bean> <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine"> <property name="templateResolver" ref="templateResolver" /> </bean> Html file template: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
  • 14. Standard dialect Expressions:  Variable Expressions: ${...}  Selection Variable Expressions: *{...}  Message Expressions: #{...}  Link URL Expressions: @{...}  If-then: (if) ? (then)  If-then-else: (if) ? (then) : (else)  Default: (value) ?: (defaultvalue) Using with basic objects:  #ctx : the context object.  #vars: the context variables.  #locale : the context locale.  #httpServletRequest : (only in Web Contexts) the HttpServletRequest object.  #httpSession : (only in Web Contexts) the HttpSession object.
  • 15. Expression Utility Objects:  #dates : utility methods for java.util.Date objects: formatting, component extraction, etc.  #calendars : analogous to #dates , but for java.util.Calendar objects.  #numbers : utility methods for formatting numeric objects.  #strings : utility methods for String objects: contains, startsWith, prepending/appending, etc.  #objects : utility methods for objects in general.  #bools : utility methods for boolean evaluation.  #arrays : utility methods for arrays.  #lists : utility methods for lists.  #sets : utility methods for sets.  #maps : utility methods for maps.  #aggregates : utility methods for creating aggregates on arrays or collections.  #messages : utility methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{…} syntax.  #ids : utility methods for dealing with id attributes that might be repeated.
  • 16. Dialect extension: <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine"> <property name="templateResolver" ref="templateResolver" /> <property name="additionalDialects"> <set> <bean class="org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect"/> </set> </property> </bean> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:sec=“http://www.thymeleaf.org/thymeleaf-extras-springsecurity4” xmlns:th="http://www.thymeleaf.org">
  • 17. Messages internationalization Application context: <bean id="messageSource“ class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value=“classpath:messages" /> </bean> Class path:
  • 18. Fragmentation footer.html ... <div th:fragment=“ftr"> Footer </div> <div id=“copyrights"> copyrights </div> ... Index.html <body> ... <div th:include="footer :: ftr"></div> <div th:include="footer :: #copyrights"></div> </body> <div th:fragment="frag (onevar,twovar)"> <p th:text="${onevar} + ' - ' + ${twovar}">...</p> </div> <div th:include="::frag (onevar=${value1},twovar=${value2})">
  • 19. Usage Examples Object expression: Today is: <span th:text="${#calendars.format(today,'dd MMMM yyyy')}">11 March 2016</span> Links usage: <a href="details.html" th:href="@{/order/details(orderId=${o.id})}">view</a> <a th:href="@{'/details/'+${user.login}(orderId=${o.id})}">view</a> Conditions usage: <div th:if="${user.isAdmin()} == false"> ...- <div th:if="${user.isAdmin() == false}> ... - Spring EL <tr th:class="${row.even}? 'class-name'"> ... <tr th:class="${1 > 0}? 'Yes' : 'No'"> ...
  • 20. Default expression: <span th:text=“${value}?: 'no value specified'">Some value</span> Setting attribute: <input type="submit" value="Subscribe me!" th:attr="value=#{subscribe.submit}"/> Forms: <form action="subscribe.html" th:action="@{/subscribe}"> Iteration: <tr th:each="item : ${list}"> <td th:text="${item.name}">Onions</td> <td th:text="${item.count}">2.41</td> </tr>
  • 21. Local variable: <div th:with="firstPer=${persons[0]},secondPer=${persons[1]}"> <span th:text="${secondPer.name}">Some Name</span>. </div> Set values to JavaScript: <script th:inline="javascript"> /*<![CDATA[*/ ... var username = /*[[${session.user.name}]]*/ ‘User'; ... /*]]>*/ </script> Switch: <div th:switch="${user.role}"> <p th:case="'admin'">User is an administrator</p> <p th:case="#{roles.manager}">User is a manager</p> </div>
  • 22. Summary Advatages:  Java template engine for XML, XHTML and HTML5.  Works both in web and non-web (offline) environments. No hard dependency on the Servlet API.  Several template modes: XML, XHTML 1.0 and 1.1, HTML5:  Internationalization support.  Parsed template cache  Is extensible  Not very complex in usage  Many documentation Disadvatages:  It's slowly than other templates.