Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load dropdown dynamically on AEM Dialog #95

Open
touseef4pk opened this issue May 30, 2024 · 1 comment
Open

Load dropdown dynamically on AEM Dialog #95

touseef4pk opened this issue May 30, 2024 · 1 comment

Comments

@touseef4pk
Copy link

touseef4pk commented May 30, 2024

I am using citytechinc cq complonent plugin to create components in AEM using Java classes. When I use following dropdown with hardcoded option, it works fine.

      `@ValueMapValue
       private String stores;
           
@DialogField(fieldLabel = "Stores", ranking = 10) @Selection(type = Selection.SELECT, options = {
        @Option(text = "Store1", value = "556"),
        @Option(text = "Store2 n Barrels", value = "475"),
        @Option(text = "Store3 Hive", value = "2547"),
})
public String getStores() {
    return stores;
}`

But I use following dropdown to load it dynamically using a servlet. The dropdown remains empty on the AEM dialog.

`@ValueMapValue
private String stores;

@DialogField(fieldLabel = "Stores", ranking = 10)
@Selection(type = Selection.SELECT, dataSource = "/bin/store/storeoptions.json")
public String getStores() {
    return stores;
}`

Following is my servlet

  `@Component(service = Servlet.class,
          property = {
                  "sling.servlet.methods=" + HttpConstants.METHOD_GET,
                  "sling.servlet.paths=" + "/bin/store/storeoptions"
          })
  public class StoreOptionsServlet extends SlingAllMethodsServlet {
  
  
      @Override
      protected void doGet(final SlingHttpServletRequest req,
                           final SlingHttpServletResponse resp) throws IOException {
          resp.setContentType("application/json");
  
          List<OptionItem> options = new ArrayList<>();
          options.add(new OptionItem("25365", "Store1"));
          options.add(new OptionItem("16726", "Store2"));
          options.add(new OptionItem("31280", "Store3"));
          // Add more options as needed
  
          resp.getWriter().write(new Gson().toJson(options));
      }
     }`

Any help is appriciated.

@touseef4pk
Copy link
Author

touseef4pk commented Jun 8, 2024

Ok I have found its solution. I need to use datasource and set as attribute in request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant