Created
March 27, 2016 18:50
-
-
Save nateyolles/b2325a7cc90dbb02ca71 to your computer and use it in GitHub Desktop.
AEM com.adobe.granite.confmgr.Conf example by adapting the current page
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.nateyolles.aem.slashconf.core.models; | |
import javax.annotation.PostConstruct; | |
import javax.inject.Inject; | |
import org.apache.sling.api.SlingHttpServletRequest; | |
import org.apache.sling.api.resource.ValueMap; | |
import org.apache.sling.models.annotations.Model; | |
import com.adobe.granite.confmgr.Conf; | |
import com.day.cq.wcm.api.Page; | |
/** | |
* AEM com.adobe.granite.confmgr.Conf example of getting a configuration by | |
* using adaptTo and reading various settings and defining default values. | |
*/ | |
@Model(adaptables = SlingHttpServletRequest.class) | |
public class ConfModel { | |
@Inject | |
private Page currentPage; | |
@PostConstruct | |
protected void init() { | |
final Conf conf = currentPage.adaptTo(Conf.class); | |
final ValueMap fooSettings = conf.getItem("socialmedia/foo"); | |
final String fooName = fooSettings.get("name", String.class); | |
final String fooNameAlt = fooSettings.get("nameAlt", "unavailable"); | |
final boolean fooEnabled = fooSettings.get("enabled", false); | |
final long limit = fooSettings.get("limit", 25); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment