Last active
August 29, 2015 14:14
-
-
Save toodooleedoo/ac6c61e73c5be9e6e18e to your computer and use it in GitHub Desktop.
AEM Sightly ACS Commons Generic List Server Side
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
<div data-sly-use.conf="${'com.test.test2.util.CustomList' @ listname='configuration'}" data-sly-unwrap></div> | |
<ul> | |
<li>${conf.list.hello}</li> | |
<li>${conf.list.analytics @context='scriptString'}</li> | |
</ul> |
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
/** | |
* <h1>CustomList</h1> | |
* Provides Sightly with Values from ACS Commons Generic List | |
* For additional details http://adobe-consulting-services.github.io/acs-aem-commons/features/generic-lists.html | |
* <p> | |
* | |
* @author Eric Soukenka | |
* @version 1.0 | |
* @since 2014-12-05 | |
*/ | |
package com.test.test2.util; | |
import java.util.HashMap; | |
import java.util.LinkedHashMap; | |
import java.util.List; | |
import org.apache.log4j.Logger; | |
import com.adobe.acs.commons.genericlists.GenericList; | |
import com.adobe.cq.sightly.WCMUse; | |
import com.day.cq.wcm.api.Page; | |
public class CustomList extends WCMUse { | |
static Logger log = Logger.getLogger(CustomList.class.getName()); | |
static final private String ROOTPATH = "/etc/acs-commons/lists/"; | |
private HashMap<String, String> listValues; | |
@Override | |
public void activate() throws Exception { | |
listValues = getList(); | |
} | |
public HashMap<String, String> getList() { | |
HashMap<String, String> listValues = new LinkedHashMap<String, String>(); | |
try { | |
String listName = get("listname", String.class); | |
Page listPage = getPageManager().getPage( ROOTPATH + listName); | |
GenericList genericList = listPage.adaptTo(GenericList.class); | |
List<GenericList.Item> list = genericList.getItems(); | |
for(GenericList.Item item : list) { | |
listValues.put(item.getTitle(), item.getValue()); | |
} | |
} catch (Exception e) { | |
log.error("Error in :" + e); | |
} | |
return listValues; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment