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,
Solved! Go to Solution.
Views
Replies
Total Likes
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[].
Views
Replies
Total Likes
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[].
Views
Replies
Total Likes