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

How to pass parameters to Sling Modal from Sightly Component

Avatar

Avatar
Ignite 1
Level 2
Eakambaram
Level 2

Likes

13 likes

Total Posts

38 posts

Correct Reply

3 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Ignite 1
Level 2
Eakambaram
Level 2

Likes

13 likes

Total Posts

38 posts

Correct Reply

3 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Boost 5
Boost 3
View profile
Eakambaram
Level 2

08-06-2017

Hi ,

I am trying to pass some custom parameters from my Sightly Component to Sling Model. But I am not able to read those passed parameters inside my Sling Model.

Below is my sightly code :

<sly data-sly-use.mySlingModal="${'com.adobe.website.models.ImageModel' @ colour='red', path=resource.path}"></sly>

How to read color and path in side my sling model java class.

Can you please help me in solving this.

desktop_exl_promo_600x100_weempoweryou.png

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Ignite 1
Level 2
Eakambaram
Level 2

Likes

13 likes

Total Posts

38 posts

Correct Reply

3 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Ignite 1
Level 2
Eakambaram
Level 2

Likes

13 likes

Total Posts

38 posts

Correct Reply

3 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Boost 5
Boost 3
View profile
Eakambaram
Level 2

21-06-2017

Thank you all for responding. We  have solved it as below.

@Model({adaptables=Resource.class, adaptables=SlingHttpServletRequest.class)

So that at the same time I will get my resource/Node/Content properties and the values passed to my sling modal from my sightly component.

Answers (15)

Answers (15)

Avatar

Avatar
Validate 1
Level 4
susheel
Level 4

Likes

60 likes

Total Posts

109 posts

Correct Reply

17 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 1
Level 4
susheel
Level 4

Likes

60 likes

Total Posts

109 posts

Correct Reply

17 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile
susheel
Level 4

08-03-2018

We can do with sling models as below:

import org.apache.sling.api.SlingHttpServletRequest;

import org.apache.sling.models.annotations.Model;

import org.apache.sling.models.annotations.Optional;

import org.apache.sling.models.annotations.injectorspecific.RequestAttribute;

@Model(adaptables = SlingHttpServletRequest.class)

public class TestModel {

@RequestAttribute

@Optional

private String test;

@PostConstruct

    public void init() {

        //we can read the values directly here.

    }

}

<sly data-sly-use.mySlingModal="${'TestModel' @ test='red'}"></sly>

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

07-11-2017

WCMUsePojo is a valid way if you prefer to use over Sling Models,

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

08-06-2017

What do you mean? @ inject should be available..

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

08-06-2017

Have your slingmodel be adaptable from slinghttpservlet request.

Then add two properties (colour , path), with the @inject annotation.

Avatar

Avatar
Ignite 1
Level 3
rampai
Level 3

Likes

25 likes

Total Posts

54 posts

Correct Reply

9 solutions
Top badges earned
Ignite 1
Validate 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Ignite 1
Level 3
rampai
Level 3

Likes

25 likes

Total Posts

54 posts

Correct Reply

9 solutions
Top badges earned
Ignite 1
Validate 1
Give Back 5
Give Back 3
Give Back 10
View profile
rampai
Level 3

25-07-2019

Hi,

Correction in this for the curly braces: @Model(adaptables = {Resource.class, SlingHttpServletRequest.class})

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

09-03-2018

Here is HTL and Sling models -- Adobe Experience Manager Help | Creating a HTL Repeating Data Set 6.3 Component that uses Sling Mode...

Using this approach - as you see - very little Java code. 

Avatar

Avatar
Validate 25
Level 4
BigT168
Level 4

Likes

27 likes

Total Posts

155 posts

Correct Reply

3 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
BigT168
Level 4

Likes

27 likes

Total Posts

155 posts

Correct Reply

3 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
BigT168
Level 4

07-11-2017

Thanks.

Adobe recommends to use sling model instead of WCMUsePoJo. I was curious how to adaptable two classes in above examples.

Avatar

Avatar
Ignite 1
Level 2
Eakambaram
Level 2

Likes

13 likes

Total Posts

38 posts

Correct Reply

3 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Ignite 1
Level 2
Eakambaram
Level 2

Likes

13 likes

Total Posts

38 posts

Correct Reply

3 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Boost 5
Boost 3
View profile
Eakambaram
Level 2

05-11-2017

@Model({adaptables=Resource.class, adaptables=SlingHttpServletRequest.class}).

I was trying to pass some parameters/values from my sighlty html to my sling model, once we receive those parameters in our java we have some custom process requirement for those parameters and have to return some value found in repository to sighlty.

You can try the adaptables way. Another way is we can change our approach from sling model to wcmuse pojo way for this component alone.

Sighlty code snippet for passing some parameters (Those parameters are not authored by the author) from sightly component to Java/WCMUsePojo class

<sly data-sly-use.customPropReader="${'com.yourcompany.division.project.CustomPropReader' @ properties='prop1,prop2'}"></sly>

WCM use pojo Java code to read those parameters.

public class CustomPropReader extends WCMUsePojo {

/**

* custom biz logic applied value map

*/

private HashMap customProcessedProps;

@Override

public void activate() {

String property = get("properties", String.class) != null ? get("properties", String.class) : "";

String[] propertyList = property.split(",");

//We will get all values in propertyList string array. We can loop through those each value and apply custom logic

//One we got the results we can send them back to Sightly

customProcessedProps = new HashMap<String, String> ();

for (String property : propertyList) {

//apply custom logic to each property string and put that in map.

customProcessedProps.put(property, applyCustomBizLogic(property));

}

}

/**

* get ValueMap of inheritedPageProperties

*

* @return HashMap

*/

public HashMap getCustomProcessedProp() {

return customProcessedProps;

}

}

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

05-11-2017

You adapt always from *one* class. In case you adapt from request, you have the resource too via the getResource()

Avatar

Avatar
Validate 25
Level 4
BigT168
Level 4

Likes

27 likes

Total Posts

155 posts

Correct Reply

3 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
BigT168
Level 4

Likes

27 likes

Total Posts

155 posts

Correct Reply

3 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
BigT168
Level 4

04-11-2017

Thank you.

However, these examples are too simple. Do you have some more examples, which adaptable resource, and inject the request? or can adaptable request and resource both?

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

04-11-2017

Newer article that uses Sling Models and @ inject Creating a custom Touch UI Grid Component for Adobe Experience Manager

Avatar

Avatar
Validate 25
Level 4
BigT168
Level 4

Likes

27 likes

Total Posts

155 posts

Correct Reply

3 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
BigT168
Level 4

Likes

27 likes

Total Posts

155 posts

Correct Reply

3 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
BigT168
Level 4

04-11-2017

Hi Eakambaram:

I have the same issue, not sure if you can help me.

for @Model({adaptables=Resource.class, adaptables=SlingHttpServletRequest.class), where to close '}'. Can you share a little bit code snippet.

Appreicated.

Thanks

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

09-06-2017

We show use of HTL and Sling Models in this article -- Developing your first Experience Manager 6.3 Components

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile
Veena_Vikram
MVP

08-06-2017

Hi Eakambaram

     I hope you have read this blog HTL introduction part 4   . Feike Visser​ has put across the details here. Please check the Sling Model Section and check if this is what you are looking for

Thanks

Veena

Avatar

Avatar
Ignite 1
Level 2
Eakambaram
Level 2

Likes

13 likes

Total Posts

38 posts

Correct Reply

3 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Ignite 1
Level 2
Eakambaram
Level 2

Likes

13 likes

Total Posts

38 posts

Correct Reply

3 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Boost 5
Boost 3
View profile
Eakambaram
Level 2

08-06-2017

I tried to use @Inject. But I am not able to use @Inject as I am using a different version. Apart form  @Inject do we have any other annotation for reading the parameters passed?