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

RequestAttributes- data-sly-include

  • July 20, 2020
  • 2 replies
  • 6065 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

Nupur_Jain
Nupur_JainAccepted solution
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

 
 
v1101Author
New Participant
July 20, 2020
Thanks nupurjain for the response. Basically I want to pass the specific clientlib category details of the component to the JSP and the category details may vary based on every component.
vanegi
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!!