Created
February 7, 2016 20:13
-
-
Save yupadhyay/84ae7b17e50ebf420605 to your computer and use it in GitHub Desktop.
Accessing Hashmap in Sightly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
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.
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
thanks!