Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Context Aware configuration with unique or not-null property

Avatar

Level 9

Is it possible to specify a CA configuration as required or Not-Null or Unique.

I am exploring for a use-case where I don't want my config collection which has a key-value pair properties to be blank or duplicate. Is there is an OOTB specifier which I have missed?

 

Sample configs.

I want to avoid cases such as:-

  • "Key1": "Val1"
  • " ": "Val2"
  • "Key1": "Val3" 
@Configuration(label = "Sample CA Config", description = "Sample CA config", collection=true)
public @interface SampleConfig {
@Property(order = 1,
label = "Key,
description = "Key Name")
String key();

@Property(order = 2,
label = "Value",
description = "Value property")
String value();
}
3 Replies

Avatar

Community Advisor

Hi, 

You could use a default value after each property, something like this:

 

 

(label="Just some Property")
String myProperty() default "someValue";

 

 

But it looks like you are more interested in validation, which is not possible using the out of the box with CA properties, you don't have such options (required, non-null, unique) for a property, check here: https://sling.apache.org/apidocs/sling9/org/apache/sling/caconfig/annotation/Property.html.

Another alternative is to keep the key/value pair in the same property, separated by a special character. While this approach can make the property harder to read, it allows you to avoid the dependency between prop1 and prop2. For example:

 

 

(label="Just some Property")
String myKeyAndValue() default "key1:value1;key2:value2";

 

 

Although I understand your concern, please keep in mind that these configurations will be managed by a developer or someone with the expertise to set them correctly, not by an author. As long as you stay within this realm, you should be safe and not have to worry too much about it. Please check this thread for more information: https://cqdump.joerghoh.de/2018/04/23/content-and-configuration/ 

 

Hope this helps



Esteban Bustamante

Avatar

Level 9

yes, I was hoping to know if there was something as part of Configuration or Property itself. Thank you.