简体   繁体   中英

How to access the properties of a component from another component which lies on same page? AEM Java Sling

Assume We have component A and Component B on Home page of AEM instance. I want Component A properties value on Component B in sling java class.

Can you please provide some code to explain your answer. It would be easy for me to understand

@PostConstruct
protected void init() {
    // ArrayList<Resource> childList = new ArrayList<Resource>();
    Resource childResource = resource.getParent();
    if (childResource != null) {
        Iterator<Resource> children = childResource.listChildren();
        while (children.hasNext()) {
            Resource child = children.next();
            String parentNodeName = child.getName();
            if (parentNodeName.equals("component-a")) {
                // childList.add(child); 
                title = child.getValueMap().get("headline", "headline value");
            }
        }
    }
}

Assigned Component A property( headline ) value to Component B property( title )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM