Implementing Synchronous Loading of Title and Value Components in Adobe AEM
Hello Adobe AEM Community,
I'm currently dealing with an interesting issue related to the Anchor Link Container within my AEM project.
Here is the scenario:
I've created a page using a specific template (let's call it Template1), which has a total of eight Anchor Link Containers. Each container includes a Title (acting as the headline) and a Content Fragment (acting as the value). Notably, the Title and Value are two separate components.
The flow of loading is such that the Title component is triggered first, followed by the Value component. For the Value component, we've set a path to the Content Fragment, which may or may not include the actual value. The visibility of the Title & Value pair depends on the existence of the value in the Content Fragment. If the value exists, the Title & Value should be displayed; if not, they should be hidden.
To manage this visibility, we check the Content Fragment value first, and then adjust a node property called "isDisplayTitle" to true/false accordingly. However, there's a catch. On the first page load, all titles are hidden because the Title component loads before the Value component, preventing it from receiving the correct value. Refreshing the page resolves the issue, but this is not an optimal solution.
We attempted to employ a Resource Change Listener to address the problem, but we are unsure how to inform HTL from Java (as our understanding is that HTL can call Java, but the reverse isn't true).
Our current strategy is to develop a Servlet class that retrieves all Content Fragment values and subsequently sends the status to the title. However, we're facing difficulties calling the servlet from the Model class. Is it a rule that servlets can only interact with external I/O?
Can anyone provide a potential solution to this issue? Also, would it be a good idea to leverage JavaScript for this use case? If yes, any recommendations on the best approach would be greatly appreciated.
Thanks in advance for your valuable insights.
