Sightly : request scope variable | Community
Skip to main content
divyasekar
New Participant
November 30, 2016
Solved

Sightly : request scope variable

  • November 30, 2016
  • 8 replies
  • 3422 views

I have to use below mentioned ProductUse class in 6 different components in a same template.

<sly data-sly-use.productUseBean="com.training.use.ProductUse">

As of now i am defining this all the components. 

How to define it once in template level and use it for different components?

 

Thanks in advance,

Divya

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

What is you follow this?

https://github.com/heervisscher/htl-examples/blob/master/core/src/main/java/com/adobe/examples/htl/core/requestscope/RequestScope.java

Then you can have this in your component:

<div data-sly-use.x="com.adobe.examples.htl.core.requestscope.RequestScope"></div>
${x.hello}

8 replies

Feike_Visser1
Feike_Visser1Accepted solution
Employee
November 30, 2016

What is you follow this?

https://github.com/heervisscher/htl-examples/blob/master/core/src/main/java/com/adobe/examples/htl/core/requestscope/RequestScope.java

Then you can have this in your component:

<div data-sly-use.x="com.adobe.examples.htl.core.requestscope.RequestScope"></div>
${x.hello}

divyasekar
New Participant
November 30, 2016

No it dint work

Feike_Visser1
Employee
November 30, 2016

Is this not working?

setAttribute("x", yourBean);

In your component

${x.yourMethod}

divyasekar
New Participant
November 30, 2016

I have set productBean object in use class using request.setAttribute. But i am not able to get request attribute in a component

Feike_Visser1
Employee
November 30, 2016

You can do this via WCMUsePojo, there you have access to the request object,

divyasekar
New Participant
November 30, 2016

Thank you for your response.

I should not use any shared file. I have to use request.setAttribute and getAttribute here. How to achieve this.

 

My scenario is going to be:

I have ProductUse class and ProductBean.
In my components i use the following snippet.
<sly data-sly-use.productUseBean="com.training.use.ProductUse"></sly>
${productUseBean.productBean.productTitle}

My achievement should be:

request.setAttribute should be used in productUse class and request.getAttribute should be used in my template.

<sly data-sly-use.productUseBean="com.training.use.ProductUse"></sly> this line should be avoided my components.

could you please tell me how to achieve this.

Feike_Visser1
Employee
November 30, 2016

Or you can use data-sly-include to include a shared file.

Jitendra_S_Toma
New Participant
November 30, 2016

Hi,

Your template must have inherited some other base component. Why can't you create a simple file and override it at your template level. This simple file can have Sightly statement and it would be initialized once. 

Above statement will enable to initialize your object once but you need to set this object in request scope as well.

Good article http://aempodcast.com/2015/sightly/emulating-requestscope-variables-sightly-aem/#.WD6FcbJ97IU

divyasekar wrote...

I have to use below mentioned ProductUse class in 6 different components in a same template.

<sly data-sly-use.productUseBean="com.training.use.ProductUse">

As of now i am defining this all the components. 

How to define it once in template level and use it for different components?

 

Thanks in advance,

Divya