Expand my Community achievements bar.

SOLVED

Array Null Property

Avatar

Level 4

How to read the null property array value?

Example:

Property         type              Value

area            String[]             

 

My requirement is i want to read the property which has a value as NULL

Please help me out to fix the issue.

Thanks!

MIke

1 Accepted Solution

Avatar

Correct answer by
Level 10

Here is more information on this subject. Lets assume that we have this property that is a String array:

[img]StringArr.png[/img]

As you can see -- testprop is empty and a String[]. To read this value - you use the JCR API and the following code:

// Retrieve content 
  Node node = root.getNode("adobe/cq"); 
  
  Property references = node.getProperty("testprop");  
  Value[] values = references.getValues();
  String myVal = values[0].getString();  
  

Here is a screenshot of debugging the code -- look at the value.

[img]StringArr2.png[/img]

View solution in original post

4 Replies

Avatar

Level 10

To read a property of a node (the prop can be String, String[], etc) - you can use the JCR API. If the prop is a String[], it will return the value. If the array is empty, this empty value is returned. To learn how to work with the JCR API, see:

http://helpx.adobe.com/experience-manager/using/programmatically-accessing-cq-content-using.html

Avatar

Correct answer by
Level 10

Here is more information on this subject. Lets assume that we have this property that is a String array:

[img]StringArr.png[/img]

As you can see -- testprop is empty and a String[]. To read this value - you use the JCR API and the following code:

// Retrieve content 
  Node node = root.getNode("adobe/cq"); 
  
  Property references = node.getProperty("testprop");  
  Value[] values = references.getValues();
  String myVal = values[0].getString();  
  

Here is a screenshot of debugging the code -- look at the value.

[img]StringArr2.png[/img]

Avatar

Level 4

smacdonald2008 wrote...

Here is more information on this subject. Lets assume that we have this property that is a String array:

As you can see -- testprop is empty and a String[]. To read this value - you use the JCR API and the following code:

// Retrieve content 
  Node node = root.getNode("adobe/cq"); 
  
  Property references = node.getProperty("testprop");  
  Value[] values = references.getValues();
  String myVal = values[0].getString();  
  

Here is a screenshot of debugging the code -- look at the value.

 

 


Hi,

Thanks for your reply.

I have tried with the below code

Node n=adminSession.getNode("/content/xxx/tra/jcr:content/parsys/columns/1/blockcontent_1");
    Property prop=n.getProperty("area");
    Value[] val=prop.getValues();
    String str=val[0].getString();

The above code is works once the property has a value.

else

its thows an Exception ArrayIndexOutOfBoundsException: 0

 

Could you please help me to go ahead

Thanks

mike

Avatar

Employee

You should check the length of the val array before reading properties from it. In this case, it would seem to be an empty array, so reading the 0 index produces that ArrayIndexOutOfBoundsException.