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

Pass an object as a parameter to sling model/wcmusepojo from sightly(HTL)

Avatar

Avatar
Level 1
jaib75117127
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
jaib75117127
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
View profile
jaib75117127
Level 1

07-10-2020

Hi,

I'm converting a JSP into sightly for a component. In that component they are setting an object as a request attribute to be used in another component. We cannot set request attributes in sightly right? So I'm trying to send this object as a parameter to a sling model/wcmusepojo to set the request attribute there but I think we can only pass string values as arguments to slingmodels/wcmusepojo right? Is there any example of passing an object as a parameter to slingmodel/wcmusepojo? 
Thanks!

AEM 6.5 htl sightly Sling Model

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Shape 1
Level 2
VeenaK
Level 2

Likes

18 likes

Total Posts

15 posts

Correct Reply

3 solutions
Top badges earned
Shape 1
Give Back
Boost 5
Boost 3
Boost 10
View profile

Avatar
Shape 1
Level 2
VeenaK
Level 2

Likes

18 likes

Total Posts

15 posts

Correct Reply

3 solutions
Top badges earned
Shape 1
Give Back
Boost 5
Boost 3
Boost 10
View profile
VeenaK
Level 2

08-10-2020

check out this similar query posted in the community that should help your problem.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-pass-parameters-to-...

Answers (3)

Answers (3)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,260 likes

Total Posts

3,139 posts

Correct Reply

886 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,260 likes

Total Posts

3,139 posts

Correct Reply

886 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

07-10-2020

Avatar

Avatar
Validate 1
MVP
Umesh_Thakur
MVP

Likes

126 likes

Total Posts

138 posts

Correct Reply

46 solutions
Top badges earned
Validate 1
Applaud 25
Ignite 3
Ignite 1
Give Back 5
View profile

Avatar
Validate 1
MVP
Umesh_Thakur
MVP

Likes

126 likes

Total Posts

138 posts

Correct Reply

46 solutions
Top badges earned
Validate 1
Applaud 25
Ignite 3
Ignite 1
Give Back 5
View profile
Umesh_Thakur
MVP

07-10-2020

You can not set request attribute from sightly but you can get it.

And also you can not pass a pure java object except String and some other like that so if you need any backend operation like setting request object you need to do it java only before it comes to the sightly.

if you still need to pass the parameter, you can do ti like that:

Sightly:

<sly data-sly-use.someObject="${'com.demo.core.models.DemoModel' @propertyOne='PropertyOne', propertyTwo='PropertyTwo'}>

Sling Model:

@Model(adaptables = { SlingHttpServletRequest.class })

public class DemoModel {

 

@Inject

private String propertyOne;

 

@Inject

private String propertyTwo;

 

//getter and setter

}

 

WCMUsePojo:

 

public class DemoUse extends WCMUsePojo {

    @Override

    public void activate() throws Exception {

        String propertyOne = get("propertyOne", String.class);

        String propertyTwo = get("propertyTwo", String.class);

              }

}

NOTE: update the name of the wcmusepojo accordingly.

this will help.

Regards

Umesh Thakur

 

Avatar

Avatar
Give Back
Level 4
Jineet_Vora
Level 4

Likes

42 likes

Total Posts

45 posts

Correct Reply

22 solutions
Top badges earned
Give Back
Ignite 1
Boost 5
Boost 3
Boost 25
View profile

Avatar
Give Back
Level 4
Jineet_Vora
Level 4

Likes

42 likes

Total Posts

45 posts

Correct Reply

22 solutions
Top badges earned
Give Back
Ignite 1
Boost 5
Boost 3
Boost 25
View profile
Jineet_Vora
Level 4

07-10-2020

Hello @jaib75117127,

You can pass the parameters in Sightly (HTL) to your Java model using the Java Use-API: https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/use-api-java.html#passing-pa...

Also, if applicable, you can use the Java Global objects like 'request': https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/global-objects.html#java-bac...

 

Jineet