Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Sling mapping between component and sling model

Avatar

Avatar
Affirm 1
Level 3
manikanthar1295
Level 3

Likes

7 likes

Total Posts

82 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
Validate 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Affirm 1
Level 3
manikanthar1295
Level 3

Likes

7 likes

Total Posts

82 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
Validate 25
Give Back 10
Give Back 5
Give Back 3
View profile
manikanthar1295
Level 3

10-05-2021

Hi,

 

how  sling mapping works for UI  component and java class

for example  there is Product component  and respective Sling model is ProductModel in we.retail code.

 

How Product component will  identify ProductModel.java as sling model class on what basis it will identy.

 

can any one  explain

let me know if any information is neeed

 

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 5
Level 5
Ritesh_M
Level 5

Likes

74 likes

Total Posts

67 posts

Correct Reply

19 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 5
Level 5
Ritesh_M
Level 5

Likes

74 likes

Total Posts

67 posts

Correct Reply

19 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
Ritesh_M
Level 5

10-05-2021

Hi @manikanthar1295 ,

 

Sling models are nothing but POJO, which includes getters of the properties. Now to have the mapping between your HTML code (which is nothing but the component html/HTL), we can use data-sly-use API, like below

<div data-sly-use.nav="org.example.NavigationModel">${nav.foo}</div>

Here 'nav' is the object carrying all properties defined in Sling Model and NavigationModel is Sling Model. so NavigationModel.java will have a setter called getFoo() which you can access by ${nav.foo}.

 

Above explanation holds true for non SPA arch type projects, For SPA project you can skip referencing Sling Model inside HTL, the mapping has been specified in React component JS, like below

MapTo('my-react-app/components/content/aem-image')(ReactImage, ImageEditConfig);

were Sling model written for 'my-react-app/components/content/aem-image' resource type will get all the properties injected by react component.


You can refer this video  Sling Model

Answers (1)

Answers (1)

Avatar

Avatar
Affirm 25
Level 5
Bhuwan_B
Level 5

Likes

85 likes

Total Posts

85 posts

Correct Reply

30 solutions
Top badges earned
Affirm 25
Establish
Give Back
Boost 50
Boost 5
View profile

Avatar
Affirm 25
Level 5
Bhuwan_B
Level 5

Likes

85 likes

Total Posts

85 posts

Correct Reply

30 solutions
Top badges earned
Affirm 25
Establish
Give Back
Boost 50
Boost 5
View profile
Bhuwan_B
Level 5

10-05-2021

Please check below article to have clarity of Sling Model:

https://aem.redquark.org/2018/10/day-10-getting-to-know-sling-models.html