SlideShare a Scribd company logo
1 of 19
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Ask the Experts – Using Sling and Adobe Experience Manager
Scott Macdonald | AEM Community Manager
Lokesh BS | Top AEM Community Member
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Agenda
 What is Sling and cheatsheet - http://docs.adobe.com/docs/en/cq/5-6-
1/developing/sling_cheatsheet.html (L)
 Sling Selectors within AEM
 Default Sling Post Servlet
 Sling APIs (S)
 Sling Models (L)
2
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
What is Sling
 REST based web framework
 Content-driven, using a JCR content repository
 A resource is a central part of Sling and it assumes everything in the JCR is a resource
 Powered by OSGi
 Scripting inside, multiple languages (JSP, server-side javascript)
 Apache Open Source project
3
* With some exceptions
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Sling Architecture
 OSGi —Sling applications are built as OSGi bundles and makes heavy use of a number of OSGi
core and services.
 Sling API — The Sling API extends the Servlet API and provides more functionality to work on the
content.
 Request Processing — Sling takes a unique approach to handling requests in that a request URL
is first resolved to a resource, then based on the resource (and only the resource) it selects the
actual servlet or script to handle the request.
 Resources —Sling considers everything in the JCR as a Resource. Based on the resource, a
servlet or script is accessed to actually handle the request.
 Servlets and Scripts — Servlets and Scripts are handled uniformly in that they are represented
as resources themselves and are accessible by a resource path.
4
* With some exceptions
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
AEM and Sling
5
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Sling CheatSheet
6
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Using the SlingPostServlet
The SlingPostServlet is a front-end to JCR operations. To select a JCR operation to
execute, the :operation request parameter is used.
Out of the box, the SlingPostServlet supports the following operations:
 property not set or empty -- Create new content or modify existing content
 delete -- Remove existing content
 move -- Move existing content to a new location
 copy -- Copy existing content to a new location
 import -- Import content structures from JSON/XML/Zip
 nop -- Explicitly requests to do nothing and just sets the response status
 checkin - Check in a versionable node
 checkout - Check out a versionable node
7
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
SlingPostServlet Examples
 Create a node named mynode. Set (or overwrite) title and body properties.
<form action="/mynode" method="POST">
<input type="text" name="title">
<textarea name = "body"
</form>
 Create a node below /mynode and make it the first child
<form action="/mynode/" method="POST">
<input type="text" name="dummy">
<input type="hidden" name=":order">
<vaule = "first"
</form>
8
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
SlingPostServlet Examples (Continued)
 Delete a node.
<form action="/node/" method="POST">
<input name =":operation" type="hidden">
<vaule = "delete" >
</form>
 Create a node below /mynode and make it the first child
<form action="/old/node/" method="POST">
<input type="hidden“ name=":operation" value="move">
<input type="hidden" name=":dest" vaule = "/new/place">
</form>
9
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
SlingPostServlet Cheatsheet
10
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
SlingPostServlet DEMO
11
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
AEM Sling APIs
 The Sling API defines a presentation framework to build Web Applications.
 The Sling API is resource centric. That is, the request URL does not address a servlet or a portlet
but a resource represented by an instance of the
org.apache.sling.api.resource.Resource interface
 The Sling API uses the URL to select a resource to be delivered. You can retrieve content from
the AEM JCR using Sling APIs. You can use the Sling API from within an OSGi bundle to retrieve a
resource from within the AEM JCR.
 To use the Sling API from within an OSGi component, you inject an
org.apache.sling.api.resource.ResourceResolverFactory instance into the service
 When using the Sling API to query the AEM JCR, you have access to helper methods that are not
available when using the JCR API. For example, the adaptTo method converts a resource into an
appropriate object representing a certain aspect of this resource
 For example to translate a Resource object to the corresponding Node object, you invoke
the adaptTo method:
Node node = resource.adaptTo(Node.class);
12
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 13
Sling API “Live” Coding
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 14
Sling Models
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Design Goals
15
 Entirely annotation driven. "Pure" POJOs
 Use of standard annotations
 OOTB supports resource properties, SlingBindings, OSGi services
 Adapt multiple objects
 Support both classes and interfaces.
 Work with existing Sling infrastructure
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
First Model
16
 POJO Class
@Model(adaptables=Resource.class)
public class TestModel{
@Inject
private String propertyName;
}
 Interface
@Model(adaptables=Resource.class)
public interface TestModel{
@Inject
String getPropertyName();
}
 Required
In Manifest file:
<Sling-Model-Packages>
org.apache.sling.models.mymodels
</Sling-Model-Packages>
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Annotations
17
@Model
declares a model class or interface
@Inject
marks a field or method as injectable
@Named
declare a name for the injection (otherwise, defaults based on field or method name).
@Optional
marks a field or method injection as optional
@Source
explicitly tie an injected field or method to a particular injector (by name). Can also be on other annotations.
@Filter
an OSGi service filter
@PostConstruct
methods to call upon model option creation (only for model classes)
@Via
use a JavaBean property of the adaptable as the source of the injection
@Default
set default values for a field or method
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Client Code
18
Model Instantiation
 adaptTo()
TestModel model = resource.adaptTo(TestModel.class)
 ModelFactory
try {
TestModel model = modelFactory.createModel(resource,
TestModel.class);
} catch (Exception e) {
//exception
}
© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

More Related Content

What's hot

HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
Prabhdeep Singh
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
Jakub Kubrynski
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 

What's hot (20)

AEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentAEM Best Practices for Component Development
AEM Best Practices for Component Development
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
 
slingmodels
slingmodelsslingmodels
slingmodels
 
AEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser CachingAEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser Caching
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
 
Osgi
OsgiOsgi
Osgi
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
 
Spring boot
Spring bootSpring boot
Spring boot
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak Khetawat
 
Adobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsAdobe Experience Manager Core Components
Adobe Experience Manager Core Components
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEM
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Aem Training Tutorials for Beginners
Aem  Training Tutorials for BeginnersAem  Training Tutorials for Beginners
Aem Training Tutorials for Beginners
 
Aem dispatcher – tips & tricks
Aem dispatcher – tips & tricksAem dispatcher – tips & tricks
Aem dispatcher – tips & tricks
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
Omnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the ThingsOmnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the Things
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 

Similar to AEM and Sling

Creating an all-purpose REST API for Cloud services using OSGi and Sling - C ...
Creating an all-purpose REST API for Cloud services using OSGi and Sling - C ...Creating an all-purpose REST API for Cloud services using OSGi and Sling - C ...
Creating an all-purpose REST API for Cloud services using OSGi and Sling - C ...
mfrancis
 

Similar to AEM and Sling (20)

Sightly_techInsight
Sightly_techInsightSightly_techInsight
Sightly_techInsight
 
Dockerizing apps for the Deployment Platform of the Month with OSGi - David B...
Dockerizing apps for the Deployment Platform of the Month with OSGi - David B...Dockerizing apps for the Deployment Platform of the Month with OSGi - David B...
Dockerizing apps for the Deployment Platform of the Month with OSGi - David B...
 
Creating an all-purpose REST API for Cloud services using OSGi and Sling - C ...
Creating an all-purpose REST API for Cloud services using OSGi and Sling - C ...Creating an all-purpose REST API for Cloud services using OSGi and Sling - C ...
Creating an all-purpose REST API for Cloud services using OSGi and Sling - C ...
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
IMMERSE'16 Introduction to adobe experience manager back end
IMMERSE'16 Introduction to adobe experience manager back endIMMERSE'16 Introduction to adobe experience manager back end
IMMERSE'16 Introduction to adobe experience manager back end
 
Open Architecture in the Adobe Marketing Cloud - Summit 2014
Open Architecture in the Adobe Marketing Cloud - Summit 2014Open Architecture in the Adobe Marketing Cloud - Summit 2014
Open Architecture in the Adobe Marketing Cloud - Summit 2014
 
Marcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL WorkbenchMarcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL Workbench
 
RESTful web apps with Apache Sling - 2013 version
RESTful web apps with Apache Sling - 2013 versionRESTful web apps with Apache Sling - 2013 version
RESTful web apps with Apache Sling - 2013 version
 
Ite express labs
Ite express labsIte express labs
Ite express labs
 
Apic dc api deep dive
Apic dc api deep dive Apic dc api deep dive
Apic dc api deep dive
 
Oracle mcs overview 1029
Oracle mcs overview 1029Oracle mcs overview 1029
Oracle mcs overview 1029
 
Modern Web Applications with Sightly
Modern Web Applications with SightlyModern Web Applications with Sightly
Modern Web Applications with Sightly
 
EVOLVE'15 | Enhance | Bob O'Conner & Kevin Nenning | Capturing Existing Cont...
EVOLVE'15 | Enhance |  Bob O'Conner & Kevin Nenning | Capturing Existing Cont...EVOLVE'15 | Enhance |  Bob O'Conner & Kevin Nenning | Capturing Existing Cont...
EVOLVE'15 | Enhance | Bob O'Conner & Kevin Nenning | Capturing Existing Cont...
 
AEM Evernote Sync
AEM Evernote SyncAEM Evernote Sync
AEM Evernote Sync
 
Integrating ONE Automation with Business Systems with the API
Integrating ONE Automation with Business Systems with the APIIntegrating ONE Automation with Business Systems with the API
Integrating ONE Automation with Business Systems with the API
 
Notes
NotesNotes
Notes
 
Integrating with Adobe Marketing Cloud - Summit 2014
Integrating with Adobe Marketing Cloud - Summit 2014Integrating with Adobe Marketing Cloud - Summit 2014
Integrating with Adobe Marketing Cloud - Summit 2014
 
Workshop: AWS DevOps Essentials: An Introductory Workshop on CI/CD Best Pract...
Workshop: AWS DevOps Essentials: An Introductory Workshop on CI/CD Best Pract...Workshop: AWS DevOps Essentials: An Introductory Workshop on CI/CD Best Pract...
Workshop: AWS DevOps Essentials: An Introductory Workshop on CI/CD Best Pract...
 
CDI Integration in OSGi - Emily Jiang
CDI Integration in OSGi - Emily JiangCDI Integration in OSGi - Emily Jiang
CDI Integration in OSGi - Emily Jiang
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 

AEM and Sling

  • 1. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Ask the Experts – Using Sling and Adobe Experience Manager Scott Macdonald | AEM Community Manager Lokesh BS | Top AEM Community Member
  • 2. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Agenda  What is Sling and cheatsheet - http://docs.adobe.com/docs/en/cq/5-6- 1/developing/sling_cheatsheet.html (L)  Sling Selectors within AEM  Default Sling Post Servlet  Sling APIs (S)  Sling Models (L) 2
  • 3. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. What is Sling  REST based web framework  Content-driven, using a JCR content repository  A resource is a central part of Sling and it assumes everything in the JCR is a resource  Powered by OSGi  Scripting inside, multiple languages (JSP, server-side javascript)  Apache Open Source project 3 * With some exceptions
  • 4. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Sling Architecture  OSGi —Sling applications are built as OSGi bundles and makes heavy use of a number of OSGi core and services.  Sling API — The Sling API extends the Servlet API and provides more functionality to work on the content.  Request Processing — Sling takes a unique approach to handling requests in that a request URL is first resolved to a resource, then based on the resource (and only the resource) it selects the actual servlet or script to handle the request.  Resources —Sling considers everything in the JCR as a Resource. Based on the resource, a servlet or script is accessed to actually handle the request.  Servlets and Scripts — Servlets and Scripts are handled uniformly in that they are represented as resources themselves and are accessible by a resource path. 4 * With some exceptions
  • 5. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. AEM and Sling 5
  • 6. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Sling CheatSheet 6
  • 7. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Using the SlingPostServlet The SlingPostServlet is a front-end to JCR operations. To select a JCR operation to execute, the :operation request parameter is used. Out of the box, the SlingPostServlet supports the following operations:  property not set or empty -- Create new content or modify existing content  delete -- Remove existing content  move -- Move existing content to a new location  copy -- Copy existing content to a new location  import -- Import content structures from JSON/XML/Zip  nop -- Explicitly requests to do nothing and just sets the response status  checkin - Check in a versionable node  checkout - Check out a versionable node 7
  • 8. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. SlingPostServlet Examples  Create a node named mynode. Set (or overwrite) title and body properties. <form action="/mynode" method="POST"> <input type="text" name="title"> <textarea name = "body" </form>  Create a node below /mynode and make it the first child <form action="/mynode/" method="POST"> <input type="text" name="dummy"> <input type="hidden" name=":order"> <vaule = "first" </form> 8
  • 9. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. SlingPostServlet Examples (Continued)  Delete a node. <form action="/node/" method="POST"> <input name =":operation" type="hidden"> <vaule = "delete" > </form>  Create a node below /mynode and make it the first child <form action="/old/node/" method="POST"> <input type="hidden“ name=":operation" value="move"> <input type="hidden" name=":dest" vaule = "/new/place"> </form> 9
  • 10. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. SlingPostServlet Cheatsheet 10
  • 11. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. SlingPostServlet DEMO 11
  • 12. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. AEM Sling APIs  The Sling API defines a presentation framework to build Web Applications.  The Sling API is resource centric. That is, the request URL does not address a servlet or a portlet but a resource represented by an instance of the org.apache.sling.api.resource.Resource interface  The Sling API uses the URL to select a resource to be delivered. You can retrieve content from the AEM JCR using Sling APIs. You can use the Sling API from within an OSGi bundle to retrieve a resource from within the AEM JCR.  To use the Sling API from within an OSGi component, you inject an org.apache.sling.api.resource.ResourceResolverFactory instance into the service  When using the Sling API to query the AEM JCR, you have access to helper methods that are not available when using the JCR API. For example, the adaptTo method converts a resource into an appropriate object representing a certain aspect of this resource  For example to translate a Resource object to the corresponding Node object, you invoke the adaptTo method: Node node = resource.adaptTo(Node.class); 12
  • 13. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 13 Sling API “Live” Coding
  • 14. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 14 Sling Models
  • 15. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Design Goals 15  Entirely annotation driven. "Pure" POJOs  Use of standard annotations  OOTB supports resource properties, SlingBindings, OSGi services  Adapt multiple objects  Support both classes and interfaces.  Work with existing Sling infrastructure
  • 16. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. First Model 16  POJO Class @Model(adaptables=Resource.class) public class TestModel{ @Inject private String propertyName; }  Interface @Model(adaptables=Resource.class) public interface TestModel{ @Inject String getPropertyName(); }  Required In Manifest file: <Sling-Model-Packages> org.apache.sling.models.mymodels </Sling-Model-Packages>
  • 17. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Annotations 17 @Model declares a model class or interface @Inject marks a field or method as injectable @Named declare a name for the injection (otherwise, defaults based on field or method name). @Optional marks a field or method injection as optional @Source explicitly tie an injected field or method to a particular injector (by name). Can also be on other annotations. @Filter an OSGi service filter @PostConstruct methods to call upon model option creation (only for model classes) @Via use a JavaBean property of the adaptable as the source of the injection @Default set default values for a field or method
  • 18. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Client Code 18 Model Instantiation  adaptTo() TestModel model = resource.adaptTo(TestModel.class)  ModelFactory try { TestModel model = modelFactory.createModel(resource, TestModel.class); } catch (Exception e) { //exception }
  • 19. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.