HashMaps in Sightly | Community
Skip to main content
October 16, 2015
Solved

HashMaps in Sightly

  • October 16, 2015
  • 2 replies
  • 1562 views

I'm a beginner trying to learn AEM.
I've a Map<Custom class, Custom Class> from which I'm able to retrieve "Key" but not able to retrieve "Value" in Sightly.
If <div data-sly-list> is used it displays the "Key", but not displaying "Value".

Example :
<div>car class</div>
<div data-sly-use.test="${'Class Name' @ slingreq=request }">
           <div data-sly-list.var="${test.getVehFeatures}">Key: ${var.xyz} Value:${test.getVehFeatures[var].name}</div>

</div>

getVehFeatures is of type Map<Custom class, Custom class>
If <div data-sly-attribute > is used, it doesn't display anything. 

Please suggest an approach for this in Sightly.

Thanks,
Karthik

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

When working with Collections  - why not use the Java part of a Sightly component? In this use case - the HashMap. Java has far better control reading a HashMap.  Read the HashMap in Java and pass the values back in JSON. 

See this community article to learn how to use Java and Sightly together: 

https://helpx.adobe.com/experience-manager/using/creating-sightly-component.html

See the Java class that extends WCMUse

2 replies

rosettar4717409
October 16, 2015

I am using sightly and java together.  I am having the same problem.  It seems as though sightly syntax does not allow the key of a hashmap to be anything other than a string.  In sightly when the key for my hashmap is a string I can make the original posters syntax work.  However when I make the key a custom class it not longer works.  (I did implement equals and hashcode in my custom class).  

I would like to know if its possible to make sightly syntax iterate a hashmap when the key of the hashmap is an custom class. 

Thanks

smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

When working with Collections  - why not use the Java part of a Sightly component? In this use case - the HashMap. Java has far better control reading a HashMap.  Read the HashMap in Java and pass the values back in JSON. 

See this community article to learn how to use Java and Sightly together: 

https://helpx.adobe.com/experience-manager/using/creating-sightly-component.html

See the Java class that extends WCMUse