Expand my Community achievements bar.

SOLVED

Environment specific properties for components

Avatar

Level 6

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

1 Accepted Solution

Avatar

Correct answer by
Level 8

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. 

View solution in original post

4 Replies

Avatar

Level 10

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

Avatar

Correct answer by
Level 8

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. 

Avatar

Level 6

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

Avatar

Level 8

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.