[xwiki-devs] How can we add multiple values to a dbList property using velocity
Hi, I have used $obj.set to update a dbList property value. But it selected only the value I paased in the set method. All the previously selected values were unselected. Can you help me to add/update the dbList property retaining the previous selections. Thanks, Firmusoft
Hi Firmusoft, First thing you should know is : if you want to save multiple values in the DBList field, you have to check the property "Multiple Select" of the DBList field in the XWikiClass (http://screencast.com/t/Jqpehv1K). If you want to save multiple values using velocity you should to set a java.util.List object, example : #set($values = ['one', 'two', 'three']) ## $values is an instance of java.util.List $obj.set('dblist', $values) to retrieve all values : #set($value =$obj.getProperty('dblist').value) ## you get a list of all values but be careful : $obj.get('dblist') return a String containing all values contcatenated with the separator (' ' space is the default separator) to add new values to a DBList field you shoud use (an update) : #set($values =$obj.getProperty('dblist').value) $values.add('four') ## you should check whether $values is null or not null before. $values.add('five') $obj.set('dblist', $values) I hope this help :) and sorry for my bad English. Good luck. -- Sofiane Baloul XWiki Developer 2014-03-03 15:34 GMT+01:00 firmusoft.xwiki <[email protected]>:
Hi,
I have used $obj.set to update a dbList property value. But it selected only the value I paased in the set method. All the previously selected values were unselected. Can you help me to add/update the dbList property retaining the previous selections.
Thanks, Firmusoft _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
participants (2)
-
firmusoft.xwiki -
Sofiane Baloul