Pass data from one component to another in adobe CQ

前端 未结 3 1199
既然无缘
既然无缘 2021-01-06 16:23

I\'m using Adobe CQ5. I have made two components that are independent of each other. However, I want to use data from one component in the other one. How do I achieve this?

3条回答
  •  长发绾君心
    2021-01-06 17:27

    While there is nothing wrong with @kmb's answer, I almost always prefer to use higher level Apis than lower level ones. In the case of CQ, this means using the sling resource API instead of the JCR node API.

    That would look something like this, assuming the same structure of the 2 components on a single page as he laid out.

    Resource r = resourceResolver.getResource(currentResource, "../component2");
    if(r != null) {
        ValueMap props = r.adaptTo(ValueMap.class);
        String somePropertyValue = props.get("someProperty", "");
    }
    

提交回复
热议问题