April 10, 2020
Estimated Post Reading Time ~

Change Static Dialog to Dynamic without re-authoring existing content

Almost all the time, we have fields of a component’s dialog fixed and any change in it requires a change in code. I had a use case in which all the fields had to be populated dynamically from a node that had information in its child nodes.



Some challenges that I faced were:
- The component was used in a lot of places and any change in that would have required re-authoring that I had to avoid.
- Showing all the fields on the page as the number of fields was dependent on the content code and that was not fixed.

Solution:
- Change xtype of the component to “cqinclude”
- In path property, the path of a servlet is given that returns a JSON for the dialog. The purpose of the servlet is to read the content node with which dialog had to be synced and populate it in a JSON. To make existing authored components work with it, the “name” of the existing fields of the dialog has been remaining the same. Those ways would pick the authored values in the components and new fields would remain as it is with the default value.
- Another problem was to display the values on a jsp. This can be accomplished using JSTL by simply looping over the properties of the dialog and displaying them.

<c:forEach var="entry" items="${properties}">
<c:out value="${entry.key}"/>;
</c:forEach>

This could be useful when we are unsure of the properties that we are going to have for a component. For example, if we have a component that is used for information regarding a company and initially we want to store basic things like name, registration id. Later on, if we want to add fields like turnover and stock value, that will automatically be available to the author.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.