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
Solved! Go to Solution.
Views
Replies
Total Likes
What is you follow this?
Then you can have this in your component:
<div data-sly-use.x="com.adobe.examples.htl.core.requestscope.RequestScope"></div>
${x.hello}
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Or you can use data-sly-include to include a shared file.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
You can do this via WCMUsePojo, there you have access to the request object,
Views
Replies
Total Likes
I have set productBean object in use class using request.setAttribute. But i am not able to get request attribute in a component
Views
Replies
Total Likes
Is this not working?
setAttribute("x", yourBean);
In your component
${x.yourMethod}
Views
Replies
Total Likes
No it dint work
Views
Replies
Total Likes
What is you follow this?
Then you can have this in your component:
<div data-sly-use.x="com.adobe.examples.htl.core.requestscope.RequestScope"></div>
${x.hello}
Views
Replies
Total Likes
Views
Like
Replies