request getattribute in Sightly set from slingmodel | Community
Skip to main content
HeenaMadan
New Participant
August 9, 2022

request getattribute in Sightly set from slingmodel

I am trying to get attribute value set in Slingmodel class. Below code is used to set value of attribute "mycustomparam" in sling model. 

model1.java

request.setAttribute("mycustomparam", "value");

But unable to get this value in HTL

I have tried 

${request.attribute @ mycustomparam}

 In other model2.java, i am able to get this value using request.getAttribute('mycustomparam');

Is there any way to get value in sightly instead of model?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

5 replies

arunpatidar
New Participant
August 10, 2022

why don't you write a get method to export attribute value in Sling Model to get the value in HTL?

 

e.g.

 

 

private mycustomparam; request.setAttribute("mycustomparam", value); mycustomparam = value; public String getMycustomparam(){ return mycustomparam; }

 

Translate
Arun Patidar
HeenaMadan
New Participant
August 10, 2022

@arunpatidar Use case is different. I need to set value in request parameterin model1.java andneed this value in different model model2, which si working fine in my implemenation.

Thanks

Heena

Translate
Nikhil_Verma
Level 4
August 10, 2022

Seems there isn't a way to directly access the request attributes in sightly and requires JS Use API. Here's a super short sample code to do just that: https://gist.github.com/gabrielwalt/a6a022ee65b3839d08bb4deb59211e57

 

Translate
HeenaMadan
New Participant
August 10, 2022

@nikhil_verma yup there is no way to access request getattribute directly in sightly. We can use either js or separate model to get setted value.

Translate
DEBAL_DAS
New Participant
August 9, 2022

Could you please check this https://www.linkedin.com/pulse/aem-63-request-attributes-ronak-bhayani/ if it helps.

Translate