Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

HashMaps in Sightly

karthik_nittur
Level 1
Level 1

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

1 Accepted Solution
smacdonald2008
Correct answer by
Level 10
Level 10

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

View solution in original post

0 Replies
rosettar4717409
Level 1
Level 1

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
Correct answer by
Level 10
Level 10

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

View solution in original post