set the property for single value string array data type using java | Community
Skip to main content
October 16, 2015
Solved

set the property for single value string array data type using java

  • October 16, 2015
  • 1 reply
  • 6115 views

Hi,

How to set the property for single value string array data type using java in AEM.

--------------------------------------------------------

eg: AEM  Properties

Name:color

Type:String[]

Value: ["yellow"]

-------------------------------------------------------

Java code:

content.setProperty(paraname, paramvalue[0]);

------------------------------------------------------

 

 

Please provide the solutions

 

 

Thanks in advance,

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

You can set a property as an Array the same way as other properties using the JCR API. You invoke the Node object;s setProperty method. 

Consider the following code:

 Node node = session.getNode("/content/dam/reports");

 javax.jcr.ValueFactory valueFactory = session.getValueFactory();

Node nodereport = session.getNode("/content/reports");

String[] colors ={"Red","Black","Orange","Blue"};

nodereport.setProperty("colors",colors);

 

When you run this code - you add a new property named colors to the /content/reports node -- as shown here:

[img]report.png[/img]

If you want to set a single value of the array -- you can do that too:

  nodereport.setProperty("colorssingle",colors[0]);

In this case -- singlecolor is assigned Red - and the data type of colorssingle is String -- not String[].

1 reply

smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

You can set a property as an Array the same way as other properties using the JCR API. You invoke the Node object;s setProperty method. 

Consider the following code:

 Node node = session.getNode("/content/dam/reports");

 javax.jcr.ValueFactory valueFactory = session.getValueFactory();

Node nodereport = session.getNode("/content/reports");

String[] colors ={"Red","Black","Orange","Blue"};

nodereport.setProperty("colors",colors);

 

When you run this code - you add a new property named colors to the /content/reports node -- as shown here:

[img]report.png[/img]

If you want to set a single value of the array -- you can do that too:

  nodereport.setProperty("colorssingle",colors[0]);

In this case -- singlecolor is assigned Red - and the data type of colorssingle is String -- not String[].