RequestAttributes- data-sly-include | Community
Skip to main content
Level 5
July 20, 2020
Solved

RequestAttributes- data-sly-include

  • July 20, 2020
  • 2 replies
  • 6082 views

Hello All - Can I use the request-attributes in data-sly-include like the below so that I can use the values in JSP.
E.g.
<sly data-sly-include="${ '/apps/project-name/components/../manipulate.jsp' @ requestAttributes='abc.html'}" />

 

Please confirm if the syntax is correct. if so,  what is the parameter name should I use it to get the value?

<%= request.getParameter("param") %>

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 Nupur_Jain

Hi @v1101 

 

In order to pass values to JSP, you are in right direction to use requestAttributes. But the parameter requestAttributes takes a map instead of a single value. In order to set a map and then pass as request parameter refer https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/block-statements.html#request-attributes.

 

 

public class Settings extends WCMUsePojo { // used to pass is requestAttributes to data-sly-resource public Map<String, Object> settings = new HashMap<String, Object>(); @Override public void activate() throws Exception { settings.put("property1", "abc.html"); } }

 

you can also use sling model to set key value pairs.

 

you can then call jsp like this:

 

<sly data-sly-use.myclass="com.adobe.examples.htl.core.hashmap.Settings" data-sly-include="${ '/apps/project-name/components/../manipulate.jsp' @ requestAttributes=myclass.settings}" />

 

 
In JSP file, you can get this property value like :

 

<%@include file="/libs/granite/ui/global.jsp"%> <%=request.getAttribute("property1")%>​

 

 

you can not use getparameter as it will provide you query parameter in the URL.

 

Hope it helps!

Thanks!

Nupur

 
 

2 replies

vanegi
Adobe Employee
Adobe Employee
July 20, 2020

Hi @v1101 ,

Yes, you can pass request-attributes [0] to data-sly-include and data-sly-resource in order to use them in the receiving HTL-script. This allows you to properly pass-in parameters into scripts or components:

 

<sly data-sly-include="${ 'something.html' @ requestAttributes=a_map_of_attributes}" />


[0]: https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/block-statements.html#request-attributes

 

In regards to accessing the parameter name, check https://stackoverflow.com/questions/1890438/how-to-get-parameters-from-the-url-with-jsp for more details.

 

 

Thanks!!

 

 

 

Nupur_Jain
Adobe Employee
Nupur_JainAdobe EmployeeAccepted solution
Adobe Employee
July 20, 2020

Hi @v1101 

 

In order to pass values to JSP, you are in right direction to use requestAttributes. But the parameter requestAttributes takes a map instead of a single value. In order to set a map and then pass as request parameter refer https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/block-statements.html#request-attributes.

 

 

public class Settings extends WCMUsePojo { // used to pass is requestAttributes to data-sly-resource public Map<String, Object> settings = new HashMap<String, Object>(); @Override public void activate() throws Exception { settings.put("property1", "abc.html"); } }

 

you can also use sling model to set key value pairs.

 

you can then call jsp like this:

 

<sly data-sly-use.myclass="com.adobe.examples.htl.core.hashmap.Settings" data-sly-include="${ '/apps/project-name/components/../manipulate.jsp' @ requestAttributes=myclass.settings}" />

 

 
In JSP file, you can get this property value like :

 

<%@include file="/libs/granite/ui/global.jsp"%> <%=request.getAttribute("property1")%>​

 

 

you can not use getparameter as it will provide you query parameter in the URL.

 

Hope it helps!

Thanks!

Nupur

 
 
Nupur_Jain
Adobe Employee
Adobe Employee
July 22, 2020

Hi @v1101 

 

Can you confirm test.jsp is present in the same folder where you are including 

<sly data-sly-use.category="com.test.testpkg.aem.core.models.Settings"
data-sly-include="{'test.jsp' @ requestAttributes=category.settings}"></sly> in HTL/Sightly HTML file.

 

test.jsp is relative path, so it expects test.jsp in the same folder. If the file is not present in same folder, you will have to include file with absolute path.