I've started working in Sightly just this week, so I'm pretty new to this. But, while working with it, I got a requirement of passing data from back-end to front end in the form of a Map containing keys of Page type and corresponding values of List<Page> type as seen in the following signature :
public Map<Page, List<Page>> getComponentMap();
Now the documentation on https://goo.gl/sylWTW states that a map can be traversed in the following way :
<p data-sly-repeat="${myMap}"> <span>key: ${item}</span> <span>value: ${myMap[item]}</span> </p>
But, when I tried it, it works if Keys are of String Type, but doesn't if I pass keys of other Object types, like 'Page' type in my case.
I tried the following code and works for displaying the keys, but throws Illegal Argument Exception after adding Line No. 6 :
1 <div data-sly-use.jcomp="JavaComponent">
2 <ul data-sly-repeat.page="${jcomp.componentMap}">
3 <li>
4 <ul>
5 <li class="parent"><a href="${page.path}.html">${page.title} :</a></li>
6 <li data-sly-repeat.subpage="${jcomp.componentMap[page]}"><a href="${subpage.path}.html">${subpage.title} </a></li>
7 </ul>
8 </li>
9 </ul>
10 </div>
Lists work fine for any type of Objects, so for my requirement of Page's Title, Path and Children, I achieved it by using a List of Map<String,Object>, where Map contains Names of Page's required info.
I don't know if it is supposed to be like that or not for Map or I'm doing something wrong, but it would be of a great help to know the reason and/or a better work-around for similar cases.
Congratulations for your hard work.
and thanks for post
Views
Replies
Total Likes
When working with HTL (Sightly); you can have a Java portion of the component. In your case; I would traverse the Map using Java and pass the results to the client using JSON data structure. Make use of Java.
Since this response was written - we have created many HELPX articles that work with collections - ie - https://helpx.adobe.com/experience-manager/using/htl_news.html
You can watch video too on this article -- http://scottsdigitalcommunity.blogspot.ca/2017/01/creating-adobe-experience-manager.html
Thanks Scott... Actually this works fine but I am still looking for a solution where I can iterate over a map that has key of type "Object", using Sightly. Using JSON or map is fine but in this case I have to send too many values from Java to HTML whereas in case of object I can just send the object and access fields in HTML. That is why looking for a cleaner way of this.
Any help really appreciated.
Views
Replies
Total Likes
Here an example of using Sightly with a HashMap:
Views
Likes
Replies