SlideShare a Scribd company logo
APACHE SLING & FRIENDS TECH MEETUP 
BERLIN, 22-24 SEPTEMBER 2014 
Dynamic Components using SPA Concepts 
Andon Sikavica, Bojana Popovska
Dynamic Components 
adaptTo() 2014 2
Dynamic vs Static Components 
Initial and form-based 
components take big chunk 
of the statics 
We spend more than 90% 
of the time developing 
dynamics 
Count of Dynamic vs Statics 
(in hundreds) 
Dynamic Static 
adaptTo() 2014 3
Dynamic Component Development 
 Placeholder for dynamic component in dispatcher 
 think about what you will have in the dispatcher 
 Request dynamic component via URL 
 /content/page/_jcr_content/par/comp.dynamic.html 
 Instruct dispatcher not to cache based on selector 
 #/0042 { /type "deny" /glob "GET *.dynamic.html*" } 
adaptTo() 2014 4
Server Side Includes 
Browser Dispatcher AEM 
GET Page 
return complete Page 
<!--#include virtual= 
“${c.resourcePath}.dynamic.html}”--> 
GET dynamic component HTML 
return component HTML 
with dynamic data 
Generate 
HTML 
adaptTo() 2014 5
AJAX 
Browser Dispatcher AEM 
GET Page 
return Page with 
Placeholders 
GET dynamic component HTML 
$.ajax({ 
url: '${c.resourcePath}.dynamic.html', 
success: function(data) { 
$(“#${c.identifier}").replaceWith(data); 
}}); 
return component HTML 
with dynamic data 
Generate 
HTML 
Create 
Markup 
adaptTo() 2014 6
Summary 
 Sling Concepts 
 component-path 
 selectors 
 sling:resourceSuperType 
 Aspect-Oriented Solution 
 Sling Dynamic Include 
adaptTo() 2014 – https://www.flickr.com/photos/fabrisalvetti/489593502 image by Fabrizio Salvetti 7
What if… 
 … you have high number of dynamic 
components on a single page? 
 … your components need to communicate 
between themselves and update their state? 
 … you need to do notifications for the user? 
…basically need SPA 
adaptTo() 2014 8
Why were the usual approaches Tricky? 
They were meant to be used 
with page reloads 
They work with pre-loaded 
Markup from server 
adaptTo() 2014 - https://www.flickr.com/photos/15708236@N07/2754478731 photo by jphilipg 9
Single Page Application 
adaptTo() 2014 10
SPA Component 
 Rendering Script (JSP) 
 Cached, Inherited 
 Module (JS) 
 Cached, Composition 
 Controller 
 Handles all dynamic calls 
Abstract 
Table 
Paging 
Sorting 
adaptTo() 2014 11
Page Load 
Browser Dispatcher AEM 
GET Page 
return Markup Skeleton 
POST for Dynamic Data 
return Dynamic Data as JSON 
Serialize 
Data as 
JSON 
Render HTML 
using Template 
with dynamic data 
adaptTo() 2014 12
Technologies 
 jQuery 
 jQuery loadTemplate 
 GSON 
 Spring (MVC, AOP) 
adaptTo() 2014 13
Benefits 
 Perceived User Experience 
 Separation of front- and 
back-end engineering 
 easier development 
 prototype 
 mocked data 
adaptTo() 2014 - https://www.flickr.com/photos/mishism/5370473007 photo by Mish Sukharev 14
Showcase 
adaptTo() 2014 15
Rendering Script 
<script type=“text/html” 
id=“scheduleTableTemplate”> 
<tr> 
<td data-content=“talkName”></td> 
<td data-content =“time”></td> 
</tr> 
Static 
Markup 
</table> Template 
</script> 
class=“scheduleTable”> 
<th> 
<td>Talk Name</td> 
<td>Time</td> 
</th> 
<tbody></tbody> 
$(‘.scheduleTable tbody’).loadTemplate( 
$(‘#scheduleTableTemplate’), 
data.talks); 
<table 
<script type=“text/javascript”> 
aemdemo.scheduletable.init( 
‘http://localhost:4502/bin/mvc.do/scheduletable/getresult’); 
</script> 
Inject data 
Initialization script 
adaptTo() 2014 16
Module 
aemdemo.schedulestable = (function($, paging, sort){ 
var params; 
function init (dataUrl){ 
params.dataUrl = dataUrl; 
} 
function getDataByPage (pageNumber) { 
$.ajax { 
data : {. . .}, 
url : params.dataUrl, 
success : function (data){paging.update (data)} 
} 
} 
return { 
init:init 
} 
}(jQuery, aemdemo.paging, aemdemo.sort)); 
adaptTo() 2014 17
Controller 
@Controller 
public class ScheduleTableController { 
@RequestMapping(value = "/scheduletable/getresult", 
produces = {"application/json" }, method = POST) 
@ResponseBody 
public String getResult(@RequestParam int pageNumber) { 
ConferenceDay conferenceDay = getDataFromService(); 
return serializeData(conferenceDay); 
} 
adaptTo() 2014 18 
}
Identify and Control POSTs 
 Add Header 
$.ajaxPrefilter(function (options, originalOptions, jqXHR) { 
jqXHR.setRequestHeader('X-Request-Source', ‘spa-ajax'); 
}); 
 Check Handler 
Servlet servlet = servletResolver.resolveServlet(slingRequest); 
if (“SlingPostServlet”.equals(servlet.getClass().getSimpleName() 
&& isDynamicRequest() ) { 
// ups 
} 
adaptTo() 2014 19
Demo Project 
http://bit.ly/aemspademo 
adaptTo() 2014 20
Questions 
adaptTo() 2014 21
Thank You! 
adaptTo() 2014 22

More Related Content

PDF
SAP API Business Hub
PPTX
Apache-Flink-What-How-Why-Who-Where-by-Slim-Baltagi
DOCX
Sap plant connectivity (p co)
PPT
Cloud Computing
PDF
Dell boomi vs sap cpi
PDF
Q&A with Confluent Experts: Navigating Networking in Confluent Cloud
PPTX
Cloud Computing Principles and Paradigms: 7 enhancing cloud computing environ...
PPTX
Big Data & Hadoop Introduction
SAP API Business Hub
Apache-Flink-What-How-Why-Who-Where-by-Slim-Baltagi
Sap plant connectivity (p co)
Cloud Computing
Dell boomi vs sap cpi
Q&A with Confluent Experts: Navigating Networking in Confluent Cloud
Cloud Computing Principles and Paradigms: 7 enhancing cloud computing environ...
Big Data & Hadoop Introduction

What's hot (9)

PPTX
Resilient Distributed DataSets - Apache SPARK
PPTX
cloud computing architecture.pptx
PDF
A Collaborative Data Science Development Workflow
PPTX
Spark architecture
PPS
SAP Data Migration With LSMW - Introduction and Key Concepts
PDF
DAS Slides: Data Quality Best Practices
PDF
Supplier Integration to Ariba Network: Cloud Integration Gateway
PPTX
Harry Potter & Apache iceberg format
PPTX
metadata.pptx
Resilient Distributed DataSets - Apache SPARK
cloud computing architecture.pptx
A Collaborative Data Science Development Workflow
Spark architecture
SAP Data Migration With LSMW - Introduction and Key Concepts
DAS Slides: Data Quality Best Practices
Supplier Integration to Ariba Network: Cloud Integration Gateway
Harry Potter & Apache iceberg format
metadata.pptx
Ad

Viewers also liked (20)

PPTX
Dynamic components using SPA concepts in AEM
PPTX
Bridging the Gap: Single-Page Apps and AEM
PDF
Build single page applications using AngularJS on AEM
PDF
Sling Dynamic Include
PPTX
EVOLVE'16 | Enhance | Paul McMahon | Approaches to Leveraging AEM Within a Si...
PDF
AEM Best Practices for Component Development
PPTX
Cqcon2015
PPTX
Build single page applications using AngularJS on AEM
PDF
CRX2Oak - all the secrets of repository migration
PPTX
content modelling for personalization
PDF
[143]Inside fuse deview 2016
PPTX
Creating Real-Time Data Mashups with Node.JS and Adobe CQ
PDF
AEM Sightly Deep Dive
PDF
REST in AEM
PDF
The six key steps to AEM architecture
PPTX
Adobe Meetup AEM Architecture Sydney 2015
PDF
AEM Sightly Template Language
PDF
Microservices Architecture for AEM
PPTX
Four approaches to integrate aem with external systems by Jan Kuzniak
PPTX
Stacking the Odds for Authentic Growth
Dynamic components using SPA concepts in AEM
Bridging the Gap: Single-Page Apps and AEM
Build single page applications using AngularJS on AEM
Sling Dynamic Include
EVOLVE'16 | Enhance | Paul McMahon | Approaches to Leveraging AEM Within a Si...
AEM Best Practices for Component Development
Cqcon2015
Build single page applications using AngularJS on AEM
CRX2Oak - all the secrets of repository migration
content modelling for personalization
[143]Inside fuse deview 2016
Creating Real-Time Data Mashups with Node.JS and Adobe CQ
AEM Sightly Deep Dive
REST in AEM
The six key steps to AEM architecture
Adobe Meetup AEM Architecture Sydney 2015
AEM Sightly Template Language
Microservices Architecture for AEM
Four approaches to integrate aem with external systems by Jan Kuzniak
Stacking the Odds for Authentic Growth
Ad

Similar to Dynamic Components using Single-Page-Application Concepts in AEM/CQ (20)

PDF
Intro to jQuery @ Startup Institute
PPTX
User Interface Patterns and Nuxeo
PDF
IBM Connect 2014 - AD205: Creating State-of-the-Art Web Applications with Dom...
PPT
PPTX
Single Page Applications: Your Browser is the OS!
PDF
Webinar about Spring Data Neo4j 4
PPT
PPTX
That's Rich! Putting a smile on ADF Faces (ODTUG Kaleidoscope 2009)
PPTX
An Introduction to Web Components
PDF
Static is just a cache
PPT
ASP.NET 4 and AJAX
PPTX
MWLUG 2014: Modern Domino (workshop)
KEY
jQuery Anti-Patterns for Performance
PPT
Introduction to jQuery
KEY
jQuery Anti-Patterns for Performance & Compression
PDF
Frontend 'vs' Backend Getting the Right Mix
PPTX
Spsbe2012 sessie start to-jquery
PDF
Modern Web Development Understanding domains technologies and user experience...
PDF
Svelte the future of frontend development
PPT
W-JAX Performance Workshop - Web and AJAX
Intro to jQuery @ Startup Institute
User Interface Patterns and Nuxeo
IBM Connect 2014 - AD205: Creating State-of-the-Art Web Applications with Dom...
Single Page Applications: Your Browser is the OS!
Webinar about Spring Data Neo4j 4
That's Rich! Putting a smile on ADF Faces (ODTUG Kaleidoscope 2009)
An Introduction to Web Components
Static is just a cache
ASP.NET 4 and AJAX
MWLUG 2014: Modern Domino (workshop)
jQuery Anti-Patterns for Performance
Introduction to jQuery
jQuery Anti-Patterns for Performance & Compression
Frontend 'vs' Backend Getting the Right Mix
Spsbe2012 sessie start to-jquery
Modern Web Development Understanding domains technologies and user experience...
Svelte the future of frontend development
W-JAX Performance Workshop - Web and AJAX

More from Netcetera (20)

PDF
Payment trend scouting - Kurt Schmid, Netcetera
PDF
Boost your approved transaction volume - Ana Vuksanovikj Vaneska, Netcetera
PDF
Increase conversion, convenience and security in e-commerce checkouts - Silke...
PDF
3-D Secure 2.0 - Stephan Rüdisüli, Netcetera & Patrick Juffern, INFORM
PDF
Digital Payment in 2020 - Kurt Schmid, Netcetera
PDF
AI First. Erfolgsfaktoren für künstliche Intelligenz im Unternehmen
PPTX
Augmenting Maintenance
PDF
Front-end up front
PDF
The future of Prototpying
PDF
EMV Secure Remote Commerce (SRC)
PPTX
Online shopping technology in the fast lane?
PDF
Merchant tokenization and EMV® Secure Remote Commerce
PDF
Seamless 3-D Secure e-commerce experience
PPTX
Augmenting Health Care
PDF
Driving transactional growth with 3-D Secure
PDF
Digital Payment Quo Vadis
PDF
EMV® Secure Remote Commerce
PDF
Context: The missing ingredient in multilingual software translation
PDF
Digital Payments - Netcetera Innovation Summit 2018
PDF
"Whats up and new at Netcetera?" - Netcetera Innovation Summit 2018
Payment trend scouting - Kurt Schmid, Netcetera
Boost your approved transaction volume - Ana Vuksanovikj Vaneska, Netcetera
Increase conversion, convenience and security in e-commerce checkouts - Silke...
3-D Secure 2.0 - Stephan Rüdisüli, Netcetera & Patrick Juffern, INFORM
Digital Payment in 2020 - Kurt Schmid, Netcetera
AI First. Erfolgsfaktoren für künstliche Intelligenz im Unternehmen
Augmenting Maintenance
Front-end up front
The future of Prototpying
EMV Secure Remote Commerce (SRC)
Online shopping technology in the fast lane?
Merchant tokenization and EMV® Secure Remote Commerce
Seamless 3-D Secure e-commerce experience
Augmenting Health Care
Driving transactional growth with 3-D Secure
Digital Payment Quo Vadis
EMV® Secure Remote Commerce
Context: The missing ingredient in multilingual software translation
Digital Payments - Netcetera Innovation Summit 2018
"Whats up and new at Netcetera?" - Netcetera Innovation Summit 2018

Recently uploaded (20)

PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Sustainable Sites - Green Building Construction
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Digital Logic Computer Design lecture notes
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Construction Project Organization Group 2.pptx
PDF
composite construction of structures.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
PPT on Performance Review to get promotions
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Sustainable Sites - Green Building Construction
bas. eng. economics group 4 presentation 1.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Digital Logic Computer Design lecture notes
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Construction Project Organization Group 2.pptx
composite construction of structures.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT on Performance Review to get promotions
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx

Dynamic Components using Single-Page-Application Concepts in AEM/CQ

  • 1. APACHE SLING & FRIENDS TECH MEETUP BERLIN, 22-24 SEPTEMBER 2014 Dynamic Components using SPA Concepts Andon Sikavica, Bojana Popovska
  • 3. Dynamic vs Static Components Initial and form-based components take big chunk of the statics We spend more than 90% of the time developing dynamics Count of Dynamic vs Statics (in hundreds) Dynamic Static adaptTo() 2014 3
  • 4. Dynamic Component Development  Placeholder for dynamic component in dispatcher  think about what you will have in the dispatcher  Request dynamic component via URL  /content/page/_jcr_content/par/comp.dynamic.html  Instruct dispatcher not to cache based on selector  #/0042 { /type "deny" /glob "GET *.dynamic.html*" } adaptTo() 2014 4
  • 5. Server Side Includes Browser Dispatcher AEM GET Page return complete Page <!--#include virtual= “${c.resourcePath}.dynamic.html}”--> GET dynamic component HTML return component HTML with dynamic data Generate HTML adaptTo() 2014 5
  • 6. AJAX Browser Dispatcher AEM GET Page return Page with Placeholders GET dynamic component HTML $.ajax({ url: '${c.resourcePath}.dynamic.html', success: function(data) { $(“#${c.identifier}").replaceWith(data); }}); return component HTML with dynamic data Generate HTML Create Markup adaptTo() 2014 6
  • 7. Summary  Sling Concepts  component-path  selectors  sling:resourceSuperType  Aspect-Oriented Solution  Sling Dynamic Include adaptTo() 2014 – https://www.flickr.com/photos/fabrisalvetti/489593502 image by Fabrizio Salvetti 7
  • 8. What if…  … you have high number of dynamic components on a single page?  … your components need to communicate between themselves and update their state?  … you need to do notifications for the user? …basically need SPA adaptTo() 2014 8
  • 9. Why were the usual approaches Tricky? They were meant to be used with page reloads They work with pre-loaded Markup from server adaptTo() 2014 - https://www.flickr.com/photos/15708236@N07/2754478731 photo by jphilipg 9
  • 10. Single Page Application adaptTo() 2014 10
  • 11. SPA Component  Rendering Script (JSP)  Cached, Inherited  Module (JS)  Cached, Composition  Controller  Handles all dynamic calls Abstract Table Paging Sorting adaptTo() 2014 11
  • 12. Page Load Browser Dispatcher AEM GET Page return Markup Skeleton POST for Dynamic Data return Dynamic Data as JSON Serialize Data as JSON Render HTML using Template with dynamic data adaptTo() 2014 12
  • 13. Technologies  jQuery  jQuery loadTemplate  GSON  Spring (MVC, AOP) adaptTo() 2014 13
  • 14. Benefits  Perceived User Experience  Separation of front- and back-end engineering  easier development  prototype  mocked data adaptTo() 2014 - https://www.flickr.com/photos/mishism/5370473007 photo by Mish Sukharev 14
  • 16. Rendering Script <script type=“text/html” id=“scheduleTableTemplate”> <tr> <td data-content=“talkName”></td> <td data-content =“time”></td> </tr> Static Markup </table> Template </script> class=“scheduleTable”> <th> <td>Talk Name</td> <td>Time</td> </th> <tbody></tbody> $(‘.scheduleTable tbody’).loadTemplate( $(‘#scheduleTableTemplate’), data.talks); <table <script type=“text/javascript”> aemdemo.scheduletable.init( ‘http://localhost:4502/bin/mvc.do/scheduletable/getresult’); </script> Inject data Initialization script adaptTo() 2014 16
  • 17. Module aemdemo.schedulestable = (function($, paging, sort){ var params; function init (dataUrl){ params.dataUrl = dataUrl; } function getDataByPage (pageNumber) { $.ajax { data : {. . .}, url : params.dataUrl, success : function (data){paging.update (data)} } } return { init:init } }(jQuery, aemdemo.paging, aemdemo.sort)); adaptTo() 2014 17
  • 18. Controller @Controller public class ScheduleTableController { @RequestMapping(value = "/scheduletable/getresult", produces = {"application/json" }, method = POST) @ResponseBody public String getResult(@RequestParam int pageNumber) { ConferenceDay conferenceDay = getDataFromService(); return serializeData(conferenceDay); } adaptTo() 2014 18 }
  • 19. Identify and Control POSTs  Add Header $.ajaxPrefilter(function (options, originalOptions, jqXHR) { jqXHR.setRequestHeader('X-Request-Source', ‘spa-ajax'); });  Check Handler Servlet servlet = servletResolver.resolveServlet(slingRequest); if (“SlingPostServlet”.equals(servlet.getClass().getSimpleName() && isDynamicRequest() ) { // ups } adaptTo() 2014 19