When Sightly Meets Slice by Tomasz Niedźwiedź
-
Upload
aem-hub -
Category
Technology
-
view
942 -
download
0
Transcript of When Sightly Meets Slice by Tomasz Niedźwiedź
![Page 1: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/1.jpg)
When Sightly Meets SliceTomasz Niedźwiedź
Software Engineer
![Page 2: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/2.jpg)
![Page 3: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/3.jpg)
<%@ include file="/libs/foundation/global.jsp" %><% // Some Java %><script> //JavaScript anyone? </script><style> /* Inline CSS rules! */ </style><% // Some more Java %><h1>If you’re careful enough, you can find HTML</h1><c:if test="someVariableSetSomewhere"> <p>HTML elements are best mixed with JSP tags</p></c:if>
Java Server Pages – The Good, the Bad and the Very Ugly
![Page 4: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/4.jpg)
<%@ include file="/libs/foundation/global.jsp" %><% // Some Java %><script> //JavaScript anyone? </script><style> /* Inline CSS rules! */ </style><% // Some more Java %><h1>If you’re careful enough, you can find HTML</h1><c:if test="someVariableSetSomewhere"> <p>HTML elements are best mixed with JSP tags</p></c:if>
Java Server Pages – The Good, the Bad and the Very Ugly
![Page 5: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/5.jpg)
• Almost plain HTML• Iteration• Hiding/showing elements• Including scripts• Access to bindings• Calling backend code
A sightly, minimalistic beauty
![Page 6: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/6.jpg)
<h1 data-sly-test="${properties.jcr:title}"> ${properties.jcr:title}</h1>
${inheritedPageProperties.twitterHandle}
<h1> ${properties.jcr:title || "Default title"}</h1>
A sightly, minimalistic beautyAccess to JCR data, really basic logic
![Page 7: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/7.jpg)
<ul data-sly-list="${ currentPage.listChildren }"> <li>${item.name}</li></ul>
<div data-sly-repeat="${currentPage.listChildren}"> ${item.name}</div>
data-sly-listdata-sly-repeat (AEM 6.1)
A sightly, minimalistic beautyIteration
![Page 8: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/8.jpg)
<template data-sly-template.validateBlank="${@validatableWithBlank, name}"> <sly data-sly-test="${!validatableWithBlank.blank}" data-sly-call="${validate @ validatable=validatableWithBlank, name=name}" data-sly-unwrap /> <div data-sly-test="${validatableWithBlank.blank && wcmmode.edit}" data-sly-include="blank.html" class="blank"> </div></template>
data-sly-templatedata-sly-calldata-sly-includedata-sly-resource
A sightly, minimalistic beautyCode reuse
![Page 9: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/9.jpg)
• Markup is clearly visible and easy to understand• Easy to learn, simple, with just the necessary set of features• Cannot affect the state of the application• Good momentum, regular improvements
What I like about it
![Page 10: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/10.jpg)
Sightly
Use interface
WCM BindingsAdapter Factories
Sling ModelsSliceJSP
![Page 11: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/11.jpg)
SliceCQ 5.3CQ 5.4CQ 5.6AEM 6.0AEM 6.1...and onwards
![Page 12: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/12.jpg)
Repository access@SliceResourcepublic class ArticleModel {
@JcrProperty("jcr:title") private String title;
@JcrProperty private String text;
//getters}
Mapping content to POJOs...
![Page 13: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/13.jpg)
Repository access@SliceResourcepublic class ArticleModel {
@JcrProperty private PublicationMetadata publicationMetadata;
@JcrProperty @Children(Author.class) private List<Author> authors;
//getters}
Slice
![Page 14: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/14.jpg)
Repository access@Model(adaptables = Resource.class)public class ArticleModel {
@Inject private PublicationMetadata publicationMetadata;
@Inject private List<Author> authors;
//getters}
Sling Models
![Page 15: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/15.jpg)
Repository accessNeat! But...
![Page 16: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/16.jpg)
Repository accessNeat! But...
![Page 17: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/17.jpg)
Slice – Does it still count?The landscape has changed
Sling Models provide an excellent way to supply components with data
Using Java classes in scipts is easier than ever
![Page 18: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/18.jpg)
Simple models are
not really the point!
![Page 19: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/19.jpg)
The killer feature of Slice?
![Page 20: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/20.jpg)
The killer feature of Slice?It’s built around Guice
![Page 21: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/21.jpg)
• The focus is not on repository access.
• It’s about a clear, well-established dependency injection model based on industry standards.
• Guice provides a consistent framework for the entire application.
• JSR 330
The killer feature of Slice?It’s built around Guice
![Page 22: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/22.jpg)
Proven to speed up development in many projects over the last several years.
The killer feature of Slice?
![Page 23: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/23.jpg)
• How many objects are to be created?
• What’s allowed to share instances?• How much control does the
programmer have?
Dependency injection with GuiceScopes
![Page 24: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/24.jpg)
• Method interception
Dependency injection with GuiceAspect Oriented Programming
![Page 25: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/25.jpg)
Dependency injection with GuiceBindings
![Page 26: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/26.jpg)
• Slice core• Slice Addons• CQ 5.5• CQ 5.6• AEM 6.0 (also compatible with
6.1)
Slice brings Guice to AEM
![Page 27: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/27.jpg)
1. Instantiate an injector in your bundle activator
2. Register OOTB modules3. Create a new module for each
logical unit of functionality4. Let the injector take care of
wiring up all of the dependencies in your whole project
How to set it up
![Page 28: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/28.jpg)
• Verbose• Complex• Exposes services to the whole
environment.• Sometimes you want simple things that
you want to hide and yet be able to inject them.
What about OSGi?It does have certain dependency injection capabilities.
![Page 29: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/29.jpg)
Peaberry used before Slice 4.1
@OsgiService annotation in newer versions
Slice & OSGi
public class MyClass {
@Inject @OsgiService ResourceResolverFactory factory; //...}
OSGi services can be injected with minimal effort
![Page 30: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/30.jpg)
• Object trees can be built thanks to dependency injection
• Not as powerful as Guice• AOP• Context management• Caching
• Less information available online on good practices and how the model works
DI in Sling ModelsPerfectly sufficient for backing your sightly scripts... but
![Page 31: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/31.jpg)
• Not a mature library• Closed• Competes with Sightly or Sling
Misconceptions
![Page 32: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/32.jpg)
Sightly & SliceCan they work together?
![Page 33: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/33.jpg)
Sightly & SliceCan they work together?
YES
![Page 34: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/34.jpg)
Using Slice in Sightly
<div data-sly-use.model="com.example.app.ArticleModel"> <span class="text">${model.text}</span> <ul data-sly-list="${model.links}"> <li><a href="${item.path}">${item.title}</a></li> </ul></div>
Sightly without Slice
![Page 35: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/35.jpg)
Using Slice in Sightly
<div data-sly-use.model="com.example.app.ArticleModel"> <span class="text">${model.text}</span> <ul data-sly-list="${model.links}"> <li><a href="${item.path}">${item.title}</a></li> </ul></div>
Sightly WITH Slice... Exactly the same
![Page 36: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/36.jpg)
Slice & Sightly• Very clear presentation layer• Visibility of markup semantics and
structure• Easy for frontent developers• Easily manageable architecture of
the AEM project• Minimal boilerplate code• Fine-grained control over objects
![Page 37: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/37.jpg)
Learn MoreSlice 4.3 (Q3 2015)• Slice persistence• New Felix console tools
Slice 5.0 (Q1 2016)• Easier consumption of models in
Servlets and Services• Mapper improvements
http://cognifide.github.io/slice/
![Page 38: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/38.jpg)
Learn MoreSlice your code in Sightly - http://goo.gl/5HTKalA presentation introducing Google Guice - https://youtu.be/hBVJbzAagfs
![Page 39: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/39.jpg)
Q&A
![Page 40: When Sightly Meets Slice by Tomasz Niedźwiedź](https://reader036.fdocuments.in/reader036/viewer/2022062900/58f35d541a28ab92318b4637/html5/thumbnails/40.jpg)
Tomasz NiedźwiedźSoftware Engineer at Cognifide
[email protected] @toniedzwiedz
Thanks for listening!