Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 14, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 14, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 14, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 14, 2025

      I test a lot of AI coding tools, and this stunning new OpenAI release just saved me days of work

      May 14, 2025

      How to use your Android phone as a webcam when your laptop’s default won’t cut it

      May 14, 2025

      The 5 most customizable Linux desktop environments – when you want it your way

      May 14, 2025

      Gen AI use at work saps our motivation even as it boosts productivity, new research shows

      May 14, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Strategic Cloud Partner: Key to Business Success, Not Just Tech

      May 14, 2025
      Recent

      Strategic Cloud Partner: Key to Business Success, Not Just Tech

      May 14, 2025

      Perficient’s “What If? So What?” Podcast Wins Gold at the 2025 Hermes Creative Awards

      May 14, 2025

      PIM for Azure Resources

      May 14, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Windows 11 24H2’s Settings now bundles FAQs section to tell you more about your system

      May 14, 2025
      Recent

      Windows 11 24H2’s Settings now bundles FAQs section to tell you more about your system

      May 14, 2025

      You can now share an app/browser window with Copilot Vision to help you with different tasks

      May 14, 2025

      Microsoft will gradually retire SharePoint Alerts over the next two years

      May 14, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Create Custom Datasource for Dropdown Fields in Context-Aware Config Editor

    Create Custom Datasource for Dropdown Fields in Context-Aware Config Editor

    May 24, 2024

    Sling Context-Aware Configuration in AEM (Adobe Experience Manager) provides the flexibility to set key value pairs for a business logic specific to a content path instead of site-wide configuration or template-wide configuration.  For example, if you want to set different values for path /content/mysite/en and /content/mysite/es, then we can use the Context-Aware Configuration at the specific path level.   

    These context-aware config values can look as simple as key value pairs with simple text field, to hardcoded drop list to select predefined values for a key.  

    The sample code snippet below is for creating a dropdown list using WCM IO.

    @Property(label = “My Dropdown”, description = “Values for my dropdown.”, property = {

    “widgetType=dropdown”,

    “dropdownOptions=[”

    + “{‘value’:’option1′,’description’:’Desc for option1′},”

    + “{‘value’:’option2′,’description’:’Desc for option2′},”

    + “{‘value’:’option3′,’description’:’Desc for option3′}”

    + “]”

    })

    String sampleDropDownParameter();

    From a business user point of view, we like to have dynamic values in the drop-down list so that we don’t have to wait for another code deployment.   

    From a developer’s point of view, in this blog, I am going to show how to solve the above requirement.  

    With WCM IO Editor extension we can implement DataSource to provide these dropdown values which makes behavior consistent especially if we are using the same source for other places. Then we can simply use the same data source in our custom data source implementation. 

    It provides DropdownOptionsProvider class to which we need to implement and write our custom logic. 

    Let’s consider we are writing dropdown options for providing the list of template paths which is required for some sort of mapping.  

    We will implement DropdownOptionsProvider which will also have configuration ability where we will provide the root path of the templates. 

    /**
    * Implementation for Template Path Data source for CAC.
    */
    @Component(service = DropdownOptionProvider.class,
    immediate = true, property = {“io.wcm.caconfig.editor.widget.dropdown.provider=templateDataSource”})
    @ServiceDescription(“Implementation For DropdownOptionProvider For Providing Templates Path “)
    @Slf4j
    @Designate(ocd= TemplatesDatasourceServiceImpl.Configuration.class)
    public final class TemplatesDatasourceServiceImpl implements DropdownOptionProvider {

    private Configuration configuration;

    @Activate
    @Modified
    public void activate(final Configuration configuration){
    this.configuration = configuration;
    }

    @Override
    public @NotNull List<DropdownOptionItem> getDropdownOptions(@NotNull final Resource resource) {
    final List<DropdownOptionItem> dropdownOptionItems = new ArrayList<>();
    final var resourceResolver = resource.getResourceResolver();
    final var templatesResource = resourceResolver.getResource(configuration.template_path());
    dropdownOptionItems.add(new DropdownOptionItem(“ALL”, “ALL – To be used for mapping in All templates”));
    if (templatesResource != null) {
    templatesResource.getChildren().forEach(templateResource -> {
    final var contentResource = templateResource.getChild(“jcr:content”);
    final var contentResourceProps = Optional.ofNullable(contentResource)
    .map(Resource::getValueMap).orElse(new ValueMapDecorator(new HashMap<>()));
    final var title = contentResourceProps.get(“jcr:title”, String.class);
    final DropdownOptionItem dropdownOptionItem =
    new DropdownOptionItem(templateResource.getPath(), title + “|”
    + templateResource.getPath());
    dropdownOptionItems.add(dropdownOptionItem);
    });
    }
    return dropdownOptionItems;
    }

    @ObjectClassDefinition(name = “Template Path For Mappings”)
    public @interface Configuration {
    @AttributeDefinition(
    name = “Template Paths”
    , description = “Template Paths”
    )
    String template_path() default “/conf/we-retail/settings/wcm/templates”;
    }

    }

    We can see that Configuration provides the ability to configure the template root path. Here we are just setting we-retail path as default path. 

    io.wcm.caconfig.editor.widget.dropdown.provider=templateDataSource 

    This will register our data source with the name of templateDataSource which we can use in Annotating the dropdown property. 

    @Property(label = “Select Template Name/Path”, description = “Name Of Template to be mapped.”, property = {
    “widgetType=dropdown”,
    “dropdownOptionsProvider=templateDataSource”
    }, order = 1)
    String getTemplatePath();

    It will appear in the editor window as pictured below.

    We can see it dynamically populated all the We Retail templates. 

    We can update logic according to required conditions like using existing Generic Lists, Pages, or any Third-party API calls. 

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleUnlocking the Power of Salesforce Data Cloud: A Dive into Data Graphs and Query Editor
    Next Article Optimize Multi-Modal AI: Part 2

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 15, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-4695 – PHPGurukul Cyber Cafe Management System SQL Injection

    May 15, 2025
    Leave A Reply Cancel Reply

    Hostinger

    Continue Reading

    7 Different Types of Keys in DBMS

    Development

    Copilot will be enhanced with ability to keep track of Teams group chats more efficiently

    Operating Systems

    This AI Research from Cohere Discusses Model Evaluation Using a Panel of Large Language Models Evaluators (PoLL)

    Development

    Supporters of Chromium-Based Browsers: La Nuova Iniziativa della Linux Foundation per Sostenere l’Innovazione e la Trasparenza nell’Ecosistema Chromium

    Linux
    Hostinger

    Highlights

    Distribution Release: CRUX 3.8

    April 21, 2025

    The DistroWatch news feed is brought to you by TUXEDO COMPUTERS. The CRUX distribution is a lightweight operating system with software added through a collection of application ports. CRUX 3.8 is the first release in about three years and features upgrades across the system. “CRUX 3.8 comes with a multilib toolchain which includes glibc 2.40, GCC 14.2.0 and Binutils….

    Own an Apple Watch? You could get part of a $20 million payout – find out how

    January 31, 2025

    How to Make Awesome Dollars on Gumroad Platform?

    May 30, 2024

    eSentire delivers private and secure generative AI interactions to customers with Amazon SageMaker

    June 21, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.