Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Reading values between AEM Models?

Avatar

Level 8

I hava page in AEM that has a fixed component B and can have one or more components A. The value (multifield paths) of components A (@ValueMapValue) are then used in the logic of component B. 

Components A and Component B are not nested components. They are separate components with their own dialog and values. Component B has to iterate through all the components A that are configured on the page and use the values from components A to build its business logic. What would be a suggested way to solve this?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @anasustic 

 

You can get the

  1. currentPage in model
  2. iterate over the node using node API
  3. Check for componentA's resourceType and if exists read all the components under it (You can easily adapt each component authored under A to their models) and fetch the value for your business logic.

Hope it helps!

Thanks,
Kiran Vedantam.

View solution in original post

5 Replies

Avatar

Community Advisor

@anasustic you can make use of querybuilder in sling model of component B to get no of components of type A present on the currentPage. 

path=/content/<project>
1_property=sling:resourceType
1_property.value=<ComponentA's resouceType>
p.limit=-1


Using that result set you can do whatever you want based on your business logic.

Hope this helps,
Krishna

Avatar

Level 8

Hi @krishna_sai 

thanks for your answer. How can I do that programmatically in a model?

Avatar

Community Advisor

Hello @anasustic

 

Option-1: Your usecase is very similar to a Accordian or Tabs component, where you could limit what components can be added.

Then the resourceType of component A itself can render it.

 

Option-2: Use nested Sling Models. Example: https://levelup.gitconnected.com/aem-how-to-use-nested-multifields-in-your-components-using-a-sling-...

 

 

 

 


Aanchal Sikka

Avatar

Level 8

Thank you @aanchal-sikka 

 

My use case is not exaclty the Accordion or Tab usecase while my Component A und Component B are separate components. They are not nested. They are just allowed on the same page and Component B has to iterate through all the components A that are configured on a page to use these value in its  business logic.

Avatar

Correct answer by
Community Advisor

Hi @anasustic 

 

You can get the

  1. currentPage in model
  2. iterate over the node using node API
  3. Check for componentA's resourceType and if exists read all the components under it (You can easily adapt each component authored under A to their models) and fetch the value for your business logic.

Hope it helps!

Thanks,
Kiran Vedantam.