How to setProperty multiple values?
Hi Friends,
I wrote a function to getProperty of an node and set its for an other node.
Example: The property name: benefits , type: String[] , value: 1,2,5
When I view properties of a page, select the benefits and click Save button. It will get the benefits values and set for an other page.
The function as below work when I select only one benefits. But, It doesn't work when I select more than one benefits.
public void syncNode(ResourceChange change, String[] langCodes, String[] properties) {
try {
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
Session session = resourceResolver.adaptTo(Session.class);
Resource resourceProperty = resourceResolver.getResource(change.getPath());
for (String langCode : langCodes) {
String pathSyncProperties = getPathByLangCode(change.getPath(), langCode);
if (!pathSyncProperties.equals("") && findExistingPath(pathSyncProperties, session) != null) {
Node node = JcrUtil.createPath(pathSyncProperties, JcrConstants.NT_UNSTRUCTURED, session);
for (String property : properties) {
String propertyData = resourceProperty.getValueMap().get(property, String.class);
if (propertyData == null || property.equals("")) {
continue;
}
node.getProperty(property).getString();
node.setProperty(property, propertyData);
}
}
}
resourceResolver.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
How I can set multiple values with setProperty for a node?
Please help me,
Thank you so much,
BienHV