How to add multivalue property to jcr node through java code?

北城以北 提交于 2019-12-13 00:42:16

问题


According this answer

https://stackoverflow.com/a/18726682/2674303

I see that I can add property to node in crxde. But I don't understand how can I add multivalue property(array) to node.

Please, help.


回答1:


You have to create an array of values:

ValueFactory valueFactory = session.getValueFactory();
Node node = session.getNode("/content/path/to/my/node");
Value[] values = new Value[3];
values[0] = valueFactory.createValue("First value");
values[1]  = valueFactory.createValue("Second value");
values[2] = valueFactory.createValue("Third value");
node.setProperty("propertyName", values);

alternatively, you may use a String array:

node.setProperty("propertyName", new String[] {"First value", "Second value", "Third value"});


来源:https://stackoverflow.com/questions/27121830/how-to-add-multivalue-property-to-jcr-node-through-java-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!