Dynamic dropdown | Community
Skip to main content
Level 2
August 28, 2024
Solved

Dynamic dropdown

  • August 28, 2024
  • 3 replies
  • 995 views

We implemented dynamic dropdown in content fragment using the reference of https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/dynamic-dropdown-content-fragment-model/m-p/459200
Now, what if I want to pass the request parameter while calling the servlet. /bin/dropdownList?paramName=paramValue this is not working. Can anyone please help me with this.

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 h_kataria

The post which you have referred is to provide a datasource in content fragment by using an already registered servlet. So, for e.g if you have a servlet registered with sling:resourceType as /bin/dropdownList then you can use that on the datasource node by setting sling:resourceType property as /bin/dropdownList but you cannot add parameters to it since it will interrupt your sling resolution.

If you want to get some data from your datasource to your servlet what you can try is setting some extra property on your datasource and set the value which you want to pass e.g dummyProperty and then you can probably retrieve that datasource node in your servlet to fetch it 
For e.g

request.getResource().getChild("datasource").getValueMap().get("dummyProperty");

I haven't tried this though. But hope this helps. 

3 replies

arunpatidar
Community Advisor
Community Advisor
August 28, 2024
EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
August 28, 2024

Hi, 

Can you be more explicit on "what is not working"? Did you implement the needed changes to handle the queryParam in the servlet accordingly? You must do something like this in the servlet:

@9944223 protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) { // Get the parameter you passed String myValue = request.getParameter("paramName"); // Do whatever you need with that value

 

Hope this helps

 

Esteban Bustamante
VanitaNaAuthor
Level 2
August 28, 2024

Hi @estebanbustamante , thanks for the response.

The problem I am facing is, call is not going to servlet only that means the servlet is not triggering when I pass the queryParameter. If I don't pass any queryParameter then the servlet is triggering.

String myValue = request.getParameter("paramName");

I am using this, but firstly the servlet should trigger.

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
August 28, 2024

Can you try this http://www.sgaemsolutions.com/2019/01/dynamically-populate-drop-down-values.html ? Are you adding a debugger or log statement to check if the servlet is not being called? Or are you assuming the servlet is not called because there are not results? There could be a chance the servlet is called but the implementation is not returning correctly the values. 

Esteban Bustamante
h_kataria
Community Advisor
h_katariaCommunity AdvisorAccepted solution
Community Advisor
August 28, 2024

The post which you have referred is to provide a datasource in content fragment by using an already registered servlet. So, for e.g if you have a servlet registered with sling:resourceType as /bin/dropdownList then you can use that on the datasource node by setting sling:resourceType property as /bin/dropdownList but you cannot add parameters to it since it will interrupt your sling resolution.

If you want to get some data from your datasource to your servlet what you can try is setting some extra property on your datasource and set the value which you want to pass e.g dummyProperty and then you can probably retrieve that datasource node in your servlet to fetch it 
For e.g

request.getResource().getChild("datasource").getValueMap().get("dummyProperty");

I haven't tried this though. But hope this helps.