Skip to content

Instantly share code, notes, and snippets.

@yupadhyay
Created February 7, 2016 20:13
Show Gist options
  • Save yupadhyay/84ae7b17e50ebf420605 to your computer and use it in GitHub Desktop.
Save yupadhyay/84ae7b17e50ebf420605 to your computer and use it in GitHub Desktop.
Accessing Hashmap in Sightly
package com.test;
import java.util.HashMap;
import java.util.Map;
import com.adobe.cq.sightly.WCMUse;
public class WcmUseSample extends WCMUse {
private Map<String, String> myHashMap;
public void activate() throws Exception {
myHashMap = new HashMap<String, String>();
for (int i = 0; i < 10; ++i) {
myHashMap.put(""+i, "Hello "+i);
}
}
public Map<String,String> getMyHashMap() {
return myHashMap;
}
}
<div data-sly-use.myClass="com.test.WcmUseSample" data-sly-unwrap>
<ul data-sly-list.keyName="${myClass.getMyHashMap}">
<li>KEY: ${keyName}, VALUE: ${myClass.getMyHashMap[keyName]}</li>
</ul>
</div>
@marcoguastalli
Copy link

thanks!

@dev-ashwani-sharma
Copy link

Hi,

You have used a for loop for inserting the values into you hashmap
Is there any way of retrieving the key and value pairs simultaneously in a foreach loop.
Looking forward to hear from you.

@deepakavs
Copy link

Can I use a Tag object as a key in HashMap ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment