How to Override @Propertyoption value from run mode specific configuration ? | Community
Skip to main content
prakashr2929023
Level 2
May 17, 2018
Solved

How to Override @Propertyoption value from run mode specific configuration ?

  • May 17, 2018
  • 6 replies
  • 2993 views

Dear All,

I have created a OSGI component to read some user related setting from the /system/console/configMgr. The code for OSGI component is some thing like this.

@Component(name = "Profile Configuration", immediate = true, metatype = true)

public class ProfileConfiguration {

@Property(name = "User Name", value = "", description = "Profile username", label = "Enter User Name")

private static final String USER_NAME = "user.name";

private String username;

@Property(name = "Password", description = "Profile username", label = "Enter User Name", passwordValue = "")

private static final String PASSWORD = "user.password";

private String password;

@Property(name = "Gender", description = "Gender", label = "Gender", options = {

@PropertyOption(name = "Male", value = "male"),

@PropertyOption(name = "Female", value = "female") }, value = "female")

private static final String GENDER = "user.gender";

private String gender;

protected void activate(Map<String, Object> props){

this.username = (String) props.get(USER_NAME);

this.password  = (String) props.get(PASSWORD);

this.gender = (String) props.get(GENDER);

}

}

I want to overide the value of gender from runmode specific configuration from CRXDELITE .  I have created a sling:OsgiConfig node config folder in config folder in project structure whose name is com.practice.core.felix.osgi.samplecomponent.ProfileConfiguration. And when i supplied user.gender -> male (String). I am able to see the overridden value in the felix console. However, Gender field is showing as TextField instead of dropdown.

Could you please help?

Thanks,

Prakash

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 Techaspect_Solu

Hi Prakash,

We've tested your code snippet and we could replicate the same issue. However, we could resolve the issue by replacing the below part of your code snippet:

@Property(name = "Gender", description = "Gender", label = "Gender", options = { 

@PropertyOption(name = "Male", value = "male"), 

@PropertyOption(name = "Female", value = "female") }, value = "female")

Expected code is:

@Property(name = "Gender", description = "Gender", label = "Gender", options = { 

@PropertyOption(name = "male", value = "Male"), 

@PropertyOption(name = "female", value = "Female") }, value = "female")

FYI: The above code worked for us as expected.

This might be because, the @PropertyOption's name is used as the value, while the parameter value is used as the label in the user interface. As you've used label instead of value for sling:OsgiConfig node in CRXDE, you might be facing this issue.

Try replacing the "name" and "value" attributes from your code snippet. Hopefully this should resolve your issue. Please let us know if you still see the same issue. We'll be more than happy to help you!

Please refer the below link which says the same:

Apache Felix - SCR Annotations

Hope this helps!

Regards,

TechAspect Solutions

6 replies

joerghoh
Adobe Employee
Adobe Employee
May 17, 2018

OK, so what is the issue then?

Looks like that you "only" have problems with the display of this property (textfield instead of dropdown) in the webconsole if you have set this value using a sling:OsgiConfig node.

(Personally I would consider this as a major issue, as you configure this property via deployment, therefor there shouldn't be any need to re-set it via webconsole. And even then it's still possible..)

kind regards,

Jörg

smacdonald2008
Level 10
May 17, 2018

Can you explan why you want to over ride OSGi config values. THe point of these values is to set them in a configuration view and then read them in your OSGi class - as explained here: Reading OSGi Configuration Values for Adobe Experience Manager 6.3

prakashr2929023
Level 2
May 17, 2018

Hi Jörg,

Thanks for answering my question. As you said the functionality is working fine. However, i was just wondering is there a way to display the Gender as a dropdown instead of TextField. The disadvantage of displaying TextField instead of dropdown is one can set a value other than male/female.

Attaching the screen shots.

As shown in the above picture i have used String for user.gender. I am curious to know if there any other JCR type to set the gender as dropdown. Or is it a known limitation?

Thanks in Advance,

Prakash

joerghoh
Adobe Employee
Adobe Employee
May 17, 2018

If I understand you correctly, the problem is the fact that it worked initially, but after having specified the value via sling:OsgiConfig node, it's not displayed correctly.

I don't know how often this feature is used at all; I would not wonder if this would be a bug in the webconsole.

Regarding the importance: Yes, if it's a textfield you could enter invalid data; but when providing config via sling:OsgiConfig nodes, you can do that as well :-)

Jörg

Techaspect_Solu
Techaspect_SoluAccepted solution
Level 7
May 21, 2018

Hi Prakash,

We've tested your code snippet and we could replicate the same issue. However, we could resolve the issue by replacing the below part of your code snippet:

@Property(name = "Gender", description = "Gender", label = "Gender", options = { 

@PropertyOption(name = "Male", value = "male"), 

@PropertyOption(name = "Female", value = "female") }, value = "female")

Expected code is:

@Property(name = "Gender", description = "Gender", label = "Gender", options = { 

@PropertyOption(name = "male", value = "Male"), 

@PropertyOption(name = "female", value = "Female") }, value = "female")

FYI: The above code worked for us as expected.

This might be because, the @PropertyOption's name is used as the value, while the parameter value is used as the label in the user interface. As you've used label instead of value for sling:OsgiConfig node in CRXDE, you might be facing this issue.

Try replacing the "name" and "value" attributes from your code snippet. Hopefully this should resolve your issue. Please let us know if you still see the same issue. We'll be more than happy to help you!

Please refer the below link which says the same:

Apache Felix - SCR Annotations

Hope this helps!

Regards,

TechAspect Solutions

smacdonald2008
Level 10
May 21, 2018

Techaspect Solutions​ - great response like always!