1

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

Max_Salah
  • 2,407
  • 11
  • 39
  • 68
  • why do you need a type parameter ? Simplify your design - Just have simple Name , Value Pairs and you can determine whether it has multiple values for the key and fit it in some array. This will simplify the maintenance of the property file in future – user1428716 Jan 14 '14 at 14:39

2 Answers2

2

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(); } }

rakhi4110
  • 9,253
  • 2
  • 30
  • 49
1

To check if obj is of type String array you can do this.

System.out.println(obj instanceof String[]);

But you did this already.

In your case apparently the type is not String[] but is Object[].

Also, you can check if the first element of this Object[] is of type
String but that doesn't mean the other elements will be of type String too.

peter.petrov
  • 38,363
  • 16
  • 94
  • 159