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 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 was:
– The component was used in 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 in the content code and that was not fixed.
Solution:
– Change xtype of component to “cqinclude”
– In path property, path of a servlet is given that returns a JSON for the dialog. Purpose of 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, “name” of the existing fields of the dialog has be remain same. That ways, it would pick the authored values in the components and new fields would remain as it is with the default value.
– Other problem was to display the values on a jsp. This can be accomplished usign 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>
[/html]
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.
Hope this Helps.. π
Vivek Sachdeva
CQ5 Developer
in.linkedin.com/pub/vivek-sachdeva/20/192/934/