Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Dynamic dropdown

Avatar

Level 2

I have a use case in which AEM dialog multifield producing authoring data to be needed in a servlet for making dynamic dropdown options. Some other component which is having dropdown widget which calls the servlet using data source for dynamic dropdown. I have achieved all the requirement except one  how does servlet get to know the dynamic  path of  multifield  component are being used on the page. I also  archived this one using servlet OSGI configuration but some business reason  OSGI configuration cannot be used.

Requirement is such as.

1. multifield component responsible for storing key value pair data for dynamic dropdown.

2. Proposal is servlet needs to retrieve the multifield authoring data and it need to expose as data source for another component. 

3. Another component calls the servlet through data source.

Restriction: ACS-Commons and OSGI Config cannot be used,  

Please give you valuable thought on this.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi @sparwaiz 
This is how I understood your problem.
1. You have a component with a multifield in its dialog where you author key value pairs.
2. Another component will need to fetch those values via servlet via datasource node into a dropdown of its dialog.

  • Now your concern is in the servlet how to determine the node of the first component (specifically the one dropped on the same page) to fetch the key value pair values from to serve the dropdown. If both components are on the same page then you can fetch the currentPagePath from the request and then query over it using search via resourceType.
  • If the key value pair is stored uniquely at a singular page different from your second component. 
    Either you can store that page path at home page metadata/page properties in a field. This way you need not author at multiple places and you can pick up the path in servlet from the home page metadata.
    Or if you actually want it to be dynamic for business reason, you can query the component in your servlet via sling:resourceType under home page hierarchy to find the first component occurrence and fetch values from it.

View solution in original post

5 Replies

Avatar

Level 5

Hi,

Have a page in your structure which won't be accessible to outside world (end user), you may block on dispatcher.

This page will have a component(may be named config component) with multifield which will accept key and value .

Key can be constant predefined in code and mentioned in authoring guide, same key(constant ) will be used by author as key in multifield & the path will be value of dynamic  path of  multifield  component.

 

Now this special page path either you can hard code and will be same on all instance or atleast this special page path can be taken as osgi config. 

 

Note:-On this page we can have other author-able key value constant similar to osgi config which are not that rigid to be part of osgi config but dynamic and authorable

Avatar

Level 7

You can pass data from your datasource by setting property on your datasource Node, For e.g

<datasource
	jcr:primaryType="nt:unstructured"
	sling:resourceType="servlet_resourceType"
	multifieldPath="multifield_path"/>

 Then you can retrieve this in your servlet and process it

request.getResource().getChild("datasource").getValueMap().get("multifieldPath",
				"default_multifield_path");

Hope this helps.

Avatar

Level 3

hi @sparwaiz ,

Hope you have already found the answer. If not please check below

 

If the ask is to look for how the multifield component authored on a page in your servlet, you can get that using the "sling:resourceType" of that component from the page path.

 

  1. Author the multifield component on a page
  2. Create a servlet which will read the component dynamically based on page path using the sling:resourcetype of the multifield component
  3. Use the servlet response in the new component dialog

Sample code to fetch dynamic component from a page assuming thats your question

ResourceResolver resourceResolver = request.getResourceResolver();
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
Page multiFieldComponentPage = pageManager.getPage("multifieldPagePath");
if (null != multiFieldComponentPage) {
   Resource responsiveGridResource = resourceResolver.getResource(multifieldPagePath+ 
   "/" + JcrConstants.JCR_CONTENT+"/root/responsivegrid");
  if (null != responsiveGridResource) { 		 
  if(responsiveGridResource.getResourceType().equalsIgnoreCase("componentResourceType")) 
  {
    return  responsiveGridResource.getPath();
  }
 }
}

 

Avatar

Correct answer by
Level 7

Hi @sparwaiz 
This is how I understood your problem.
1. You have a component with a multifield in its dialog where you author key value pairs.
2. Another component will need to fetch those values via servlet via datasource node into a dropdown of its dialog.

  • Now your concern is in the servlet how to determine the node of the first component (specifically the one dropped on the same page) to fetch the key value pair values from to serve the dropdown. If both components are on the same page then you can fetch the currentPagePath from the request and then query over it using search via resourceType.
  • If the key value pair is stored uniquely at a singular page different from your second component. 
    Either you can store that page path at home page metadata/page properties in a field. This way you need not author at multiple places and you can pick up the path in servlet from the home page metadata.
    Or if you actually want it to be dynamic for business reason, you can query the component in your servlet via sling:resourceType under home page hierarchy to find the first component occurrence and fetch values from it.