How to get the current page path in a servlet mapped to a datasource
Hi All,
We have a requirement as shown below:
1. A page (PageA) will have two components
2. First component (Component A) is a path browser which allows user to link to another page (Page B).
3.Second component (Component B) has various fields and a multifield.
4. The multifield in Component B has dropdown value field which has to be populated based on the data present in Component A
5. To accomplish this, we created a dynamic dropdown datasource on the multifield item. Datasource is mapped to a servlet.
Problem statement:
The resource path that we are getting in the servlet is the resource path of the component (Component B)
Inorder to get the path of component A, we are trying to get the current page path using
"String resourcePath = (String) request.getAttribute("granite.ui.form.contentpath");"
This will return the complete path upto the first item in the multifield. /content/site/folder/pageA/jcr:content/root/container/component/multifieldItem/item0
From here we are doing a substring to "/content/site/folder/pageA/" and appending the required path i.e /jcr:content/root/container/ComponentA
So now, "/content/site/folder/pageA/jcr:content/root/container/ComponentA" will have a property which has the link to PageB, which we are using for further processing.
While using this approach, on the first time load of the dialog, the dropdown values are not getting populated. Once one multifield item is added, dialog submitted and then reopened the values are getting populated.
We also used the below to get the page path.
Enumeration<?> values = request.getHeaders("Referer"); if (values != null) { while
(values.hasMoreElements()) { String url = (String) values.nextElement();
LOGGER.info("Resource url enumeration*****" + url); } }
As the above is not highly recommended, could any of you suggest how to retrieve the path of the page where the component is authored?
Thanks!