Array Null Property | Community
Skip to main content
mikezooz
October 16, 2015
Solved

Array Null Property

  • October 16, 2015
  • 4 replies
  • 1122 views

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.
Best answer by smacdonald2008

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

smacdonald2008
October 16, 2015

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

smacdonald2008
smacdonald2008Accepted solution
October 16, 2015

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]

mikezooz
mikezoozAuthor
October 16, 2015

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

Adobe Employee
October 16, 2015

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.