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:-
@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();
}
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @Kamal_Kishor
You can write a custom validator.
https://wcm.io/caconfig/editor/validation.html
Hi @Kamal_Kishor
You can write a custom validator.
https://wcm.io/caconfig/editor/validation.html
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
yes, I was hoping to know if there was something as part of Configuration or Property itself. Thank you.
Views
Likes
Replies