I am leveraging context-aware configuration. In my sling model class, I am using the below code to read the context-aware configuration. As we know, this uses the inheritance logic to find the first available sling:configRef property. I have sling:configRef property at multiple root levels. So, In my sling model, I need to know the following two things. I don’t see any exposed methods to get these values. I have an option to use heritanceValueMap to sling:configRef property, but I would like to know if anything is exposed out of configurationbuilder or any other implementing class. We are on 6.5.3
ConfigurationBuilder configurationBuilder = resource.adaptTo(ConfigurationBuilder.class);
SampleConfig sampleConfig = configurationBuilder.as(SampleConfig.class);
Solved! Go to Solution.
Views
Replies
Total Likes
In AEM, On our content path we use the property slign:configRef to pass the path of the context aware Siteconfiguration at this path we used to have one .xml file that will have all the parameters mapped with the fields your siteconfiguration.java file. and thus if you have an object of the .java file you will get those parameters easily.
For example:
1. In our site path at : /content/my-site/us/en_us/jcr:content, we have sling:configRef pointing to /conf/my-site/us/en_us
2. In our code base at /conf/my-site/us/en_us we have on sling folder type node named sling:configs
3. Under /conf/my-site/us/en_us/sling:configs we have created on .xml file with pid of the site configuration like
com.mysite.configurations.SiteConfiguration.xml
4. in the above file we pass all the parameter that will be mapped to SiteConfiguration.java like
Java:
@Property(label = "Site ID", description = "Configurable Site ID")
String siteID();
XML:
siteID="1"
Now in sling model you will be getting reference of the SiteConfiguration like
ConfigurationBuilder configBuilder = contentResource.adaptTo(ConfigurationBuilder.class);
if (null != configBuilder) {
siteConfig = configBuilder.as(SiteConfiguration.class);
}
And then from
siteConfig.siteID();
this is how you can get the value of context aware config.
Now you need to check what are step you missed.
Hope this will help.
Umesh Thakur
Hi @LikesAEM
Please refer Context-Aware Resources and Context-Aware Configurations section from the below link. It has the details what you are looking for.
https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configurati...
Hope this helps!
Thanks!
Views
Replies
Total Likes
@LikesAEM
Please see below:
ConfigurationResourceResolver configurationResourceResolver; (You can get this as a Reference)
String contextPath = configurationResourceResolver.getContextPath(contentResource);
log.info("Context Path --> {}", contextPath);
This will give you the path from where the context aware config (i.e. sling:configRef) property is getting picked.
This is what exactly I referred in the link I provided earlier
Hope this helps!
Views
Replies
Total Likes
In AEM, On our content path we use the property slign:configRef to pass the path of the context aware Siteconfiguration at this path we used to have one .xml file that will have all the parameters mapped with the fields your siteconfiguration.java file. and thus if you have an object of the .java file you will get those parameters easily.
For example:
1. In our site path at : /content/my-site/us/en_us/jcr:content, we have sling:configRef pointing to /conf/my-site/us/en_us
2. In our code base at /conf/my-site/us/en_us we have on sling folder type node named sling:configs
3. Under /conf/my-site/us/en_us/sling:configs we have created on .xml file with pid of the site configuration like
com.mysite.configurations.SiteConfiguration.xml
4. in the above file we pass all the parameter that will be mapped to SiteConfiguration.java like
Java:
@Property(label = "Site ID", description = "Configurable Site ID")
String siteID();
XML:
siteID="1"
Now in sling model you will be getting reference of the SiteConfiguration like
ConfigurationBuilder configBuilder = contentResource.adaptTo(ConfigurationBuilder.class);
if (null != configBuilder) {
siteConfig = configBuilder.as(SiteConfiguration.class);
}
And then from
siteConfig.siteID();
this is how you can get the value of context aware config.
Now you need to check what are step you missed.
Hope this will help.
Umesh Thakur
Views
Replies
Total Likes
Views
Replies
Total Likes
you can use below API
e.g.
Conf conf = getCurrentPage().adaptTo(Conf.class);
//log.info("conf ===>After");
if (conf != null) {
dbSettings = conf.getItem("dbDetails");
dbUserName = dbSettings.get("dbUser", "No UserId found");
dbUserPwd = dbSettings.get("dbPwd", "No password found");
dbUserURI = dbSettings.get("dbUrl", "No URL found");
// log.info("Values from conf : " + dbUserName + dbUserPwd + dbUserURI);
} else {
log.info("conf is Null");
}
Views
Likes
Replies
Views
Likes
Replies