Expand my Community achievements bar.

SOLVED

BindingValueProvider & BindingValueProviderByContext Use these to get common data from Page property

Avatar

Level 3

Hi All,

 

I am trying to implement some components which reads common page property and resolve a referenced content fragment and read data from it which again is shared across many components on page. To solve this problem, I can think of below approaches.

  • Read this data again and again in my model class which does not seem optimal as I am reading this same data in many components.
  • Set values in sling request attributes which is possible solution, but I don't like this approach. AEM: Sharing Data Between Components (alexlockhart.me)
  • I am curious if I can just implement a BindingValueProvider so this property can be accessed directly in my HTL code similar to how other properties like ${currentPage}, ${properties} object is used. I like this approach but I am worried that this might cause some performance issues. I have found some sample code as below acs-aem-commons/bundle/src/main/java/com/adobe/acs/commons/wcm/properties/shared/impl/SharedComponen... but not sure if that is correct way to implement it now I also see BindingValueProviderByContext which Ideally should be used.

 

If anyone has experience and have used these and also have some sample code, they can share would be great.

Thank you for your help.

 

Thanks,

Shehjad

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi @shehjadk07 

 

Using BindingValueProvider or BindingValueProviderByContext is a great solution for sharing common data across components. It improves performance by avoiding redundant data fetches and simplifies the HTL code. I recommend testing it in your environment to ensure it meets your performance and maintainability standards.

 

idea behind the BindingValueProvider is to expose common data, such as page properties or content fragment data, as bindings in your HTL templates, making it globally accessible


BindingValueProvider, introduced in ACS AEM Commons, that supports providing context-aware bindings (like page context, resource context, etc.). It’s an even better fit when you need different bindings for different contexts (e.g., author vs publish environment).

View solution in original post

2 Replies

Avatar

Correct answer by
Level 7

Hi @shehjadk07 

 

Using BindingValueProvider or BindingValueProviderByContext is a great solution for sharing common data across components. It improves performance by avoiding redundant data fetches and simplifies the HTL code. I recommend testing it in your environment to ensure it meets your performance and maintainability standards.

 

idea behind the BindingValueProvider is to expose common data, such as page properties or content fragment data, as bindings in your HTL templates, making it globally accessible


BindingValueProvider, introduced in ACS AEM Commons, that supports providing context-aware bindings (like page context, resource context, etc.). It’s an even better fit when you need different bindings for different contexts (e.g., author vs publish environment).

Avatar

Level 3

Thank you @abhishekanand_  do you have any sample code to show the context aware binding