Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 7

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

View solution in original post

6 Replies

Avatar

Employee Advisor

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

Avatar

Level 10

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

Avatar

Level 2

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.

configuration.png

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?

configuration-display.png

Thanks in Advance,

Prakash

Avatar

Employee Advisor

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

Avatar

Correct answer by
Level 7

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