SlideShare a Scribd company logo
1 of 22
Download to read offline
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

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

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

Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
 
Getting started with hot towel spa
Getting started with hot towel spaGetting started with hot towel spa
Getting started with hot towel spa
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
OttawaJS - React
OttawaJS - ReactOttawaJS - React
OttawaJS - React
 
WordCamp Montreal 2016 WP-API + React with server rendering
WordCamp Montreal 2016  WP-API + React with server renderingWordCamp Montreal 2016  WP-API + React with server rendering
WordCamp Montreal 2016 WP-API + React with server rendering
 
Monitoring web application response times, a new approach
Monitoring web application response times, a new approachMonitoring web application response times, a new approach
Monitoring web application response times, a new approach
 
Best practices in using Salesforce Metadata API
Best practices in using Salesforce Metadata APIBest practices in using Salesforce Metadata API
Best practices in using Salesforce Metadata API
 
Get your mobile app in production in 3 months: Native and Reactive Mobile Apps
Get your mobile app in production in 3 months: Native and Reactive Mobile AppsGet your mobile app in production in 3 months: Native and Reactive Mobile Apps
Get your mobile app in production in 3 months: Native and Reactive Mobile Apps
 
Spring-training-in-bangalore
Spring-training-in-bangaloreSpring-training-in-bangalore
Spring-training-in-bangalore
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
 
Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singh
 
Rethinking Angular Architecture & Performance
Rethinking Angular Architecture & PerformanceRethinking Angular Architecture & Performance
Rethinking Angular Architecture & Performance
 
Best practices in using Salesforce Metadata API
Best practices in using Salesforce Metadata APIBest practices in using Salesforce Metadata API
Best practices in using Salesforce Metadata API
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
Presemtation Tier Optimizations
Presemtation Tier OptimizationsPresemtation Tier Optimizations
Presemtation Tier Optimizations
 
Bringing the JAMstack to the Enterprise
Bringing the JAMstack to the EnterpriseBringing the JAMstack to the Enterprise
Bringing the JAMstack to the Enterprise
 
Achievement Archive
Achievement ArchiveAchievement Archive
Achievement Archive
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 
Divide et impera
Divide et imperaDivide et impera
Divide et impera
 

Recently uploaded

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Recently uploaded (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 

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