Skip to main content
mikezooz
Level 4
Oct 16, 2015 2:26 AM UTC
Solved

Array Null Property

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 16, 2015 2:26 AM UTC

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]

4 replies

Adobe Employee
Oct 16, 2015 2:26 AM UTC

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.

Translate
mikezooz
mikezoozAuthor
Level 4
Oct 16, 2015 2:26 AM UTC

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

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 16, 2015 2:26 AM UTC

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]

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:26 AM UTC

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

Translate