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") %>
Solved! Go to Solution.
Views
Replies
Total Likes
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#reques....
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 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}" />
<%@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
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}" />
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!!
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#reques....
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 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}" />
<%@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
Views
Replies
Total Likes
Hi @v1101
In the similar way, you can send one key value pair with value equals to clientlib category to the JSP include.
Views
Replies
Total Likes
Views
Replies
Total Likes
Even if there are multiple key value pairs, there is no harm sending all pairs in include. We can not add specific pair from Map to requestAttribute, we have to send the whole map. OR either create new map with only required property and then send in requestAttribute.
Views
Replies
Total Likes
Hi @nupujain - I am getting an error while trying to invoke the jsp and passing the request attributes, I am getting an error. Can you plz advise?
<sly data-sly-use.category="com.test.testpkg.aem.core.models.Settings"
data-sly-include="{'test.jsp' @ requestAttributes=category.settings}"></sly>
Error Details:
com.adobe.cq.sightly.WCMScriptHelper Failed to locate script {'test.jsp' @ requestAttributes=category.settings}
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Likes
Replies