Hello,
is there a way to get current node or current page inside JSP?
I am playing with the data source and I would like to get all property on the current page.
Thank you so much.
Piece of code:
<%@include file="/libs/granite/ui/global.jsp"%>
<%@ page import="com.adobe.granite.ui.components.ds.DataSource" %>
<%@ page import="com.adobe.granite.ui.components.ds.ValueMapResource" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="org.apache.sling.api.wrappers.ValueMapDecorator" %>
<%@ page import="com.adobe.granite.ui.components.ds.SimpleDataSource" %>
<%@ page import="org.apache.commons.collections.iterators.TransformIterator" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.LinkedHashMap" %>
<%@ page import="org.apache.commons.collections.Transformer" %>
<%@ page import="org.apache.sling.api.resource.*" %>
<%
final Map<String, String> listSelectToRender = new LinkedHashMap<String, String>();
Resource datasource = resource.getChild("datasource");
ResourceResolver resolver = resource.getResourceResolver();
ValueMap dsProperties = ResourceUtil.getValueMap(datasource);
String genericListPath = dsProperties.get("field", String.class);
String rootPath = myPage.getProperty(genericListPath, String.class);
if(genericListPath != null) {
String[] listToken = genericListPath.split(",");
for(String token: listToken) {
listSelectToRender.put(token, token);
token
}
DataSource ds = new SimpleDataSource(new TransformIterator(listSelectToRender.keySet().iterator(), new Transformer() {
public Object transform(Object o) {
String key = (String) o;
ValueMap vm = new ValueMapDecorator(new HashMap<String, Object>());
vm.put("value", listSelectToRender);
vm.put("text", listSelectToRender.get(key));
return new ValueMapResource(resolver, new ResourceMetadata(), "nt:unstructured", vm);
}
}));
request.setAttribute(DataSource.class.getName(), ds);
}
%>
Views
Replies
Total Likes
Hi.
In that line of code have you tried using the global variable "currentPage"?
Hello,
Yes I tried to use currentPage as global variable but I got a null.
I am using this jsp inside dialog page property/
Views
Replies
Total Likes
It would be useful to know which version of AEM you are using.
Can you replace <%@include file="/libs/granite/ui/global.jsp"%> with the following?
<%@include file="/libs/foundation/global.jsp"%>
Thank you.
I am using AEM 6.2.
I will replace it.
Views
Replies
Total Likes
Any chance you found how to do this?
Views
Replies
Total Likes
See How to access the currentPage and currentNode Objects in a Sling Servlet (they discuss JSP)
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies