Search code examples
javaaemcrx

how to check pageproperty on type String[]?


I have in the dialog.xml the following property:

Now I created new page and filled this property with three values (string1, string2, string3). this property in crx jcr:content looks like this:

Name       | Type     | Value
------------------------------
myProperty | String[] | string1, string2, string3

Now I would like to access this property with java and check if it has the type String[]. I do this as follow:

boolean result = myPage.getProperties().get("myProperty") instanceof String[];

result returns "false".

How to check, if myProperty is String array ?

p.s: String.valueOf(...).get("myProperty")) returns [Ljava.lang.Object;@761139f3


Solution

  • You can try the following. It would return true if the property is multi-valued, else returns false.

    Property myProp = myPage.getProperties().get("myProperty"); boolean result = myProp.isMultiple();

    We can then get the value of the property and then check its type.

    if(result) { Value[] values = myProp.getValues(); for(Value value : values) { value.getString(); } }