Environment specific properties for components | Community
Skip to main content
selvaganesh
Level 5
October 16, 2015
Solved

Environment specific properties for components

  • October 16, 2015
  • 4 replies
  • 1743 views

I see that we can use environment specific configuration using confg.runmodes for OSGI. Is there anyway to do for a components?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by PaulMcMahon

Are you interested in controlling the configurations that are managed on the component's definition node (things like component group or sling resource super type) or configurations for the custom code you write in the JSP/Sightly of the component? I agree with Scott that you can't do that for the component definition node, but if you interested in controlling the behavior of your custom code there are a variety of ways to do that:

  • You can code your component to pull the configurations in question from a central location in your site hierarchy - like say your root site node or language node - /content/mysite or /content/mysite/en. 
  • You can create a OSGI configuration service - either specific to you component or more general and use OSGI to manage the configurations - you need to access them either via a JSP tag or a WCM Use bean (if you are coding in Sightly). 

There are multiple variations of those two approaches. Each of them has some pros and cons depending on exactly what kind of configurations you are trying manage. 

4 replies

smacdonald2008
Level 10
October 16, 2015

Components do not have the same environment config settings as OSGi bundles. All settings for components are documented here:

http://docs.adobe.com/docs/en/cq/5-6-1/developing/components.html

PaulMcMahonAccepted solution
Level 8
October 16, 2015

Are you interested in controlling the configurations that are managed on the component's definition node (things like component group or sling resource super type) or configurations for the custom code you write in the JSP/Sightly of the component? I agree with Scott that you can't do that for the component definition node, but if you interested in controlling the behavior of your custom code there are a variety of ways to do that:

  • You can code your component to pull the configurations in question from a central location in your site hierarchy - like say your root site node or language node - /content/mysite or /content/mysite/en. 
  • You can create a OSGI configuration service - either specific to you component or more general and use OSGI to manage the configurations - you need to access them either via a JSP tag or a WCM Use bean (if you are coding in Sightly). 

There are multiple variations of those two approaches. Each of them has some pros and cons depending on exactly what kind of configurations you are trying manage. 

selvaganesh
Level 5
October 16, 2015

I have created a configurable OSGI bundle.I am using sightly components(where env specific controls are present). I have created the sling:osginode based on different run modes. How can I access the properties of OSGI Bundle in Java-WCMUse of sightly component. Any interface/Class should i use ? It will be helpful if you could share some code snippet for accessing the OSGI properties external to bundle

Level 8
October 16, 2015

When you say you have created a configurable OSGI bundle do you mean you have a service or component in that bundle that is configurable? I am assuming that's what you mean. In that case you need to define getters for any configurable values on your service's interface. Then your use bean gets a reference to your service either through the SlingScriptHelper.getService method.