On 02/08/2010 06:18 PM, Guillaume Lerouge wrote:
> Hi Allen,
>
> On Mon, Feb 8, 2010 at 6:03 PM, J. Allen Q. Santos<[email protected]> wrote:
>
>> Hi,
>>
>> how do I manually add a user in XWikiAllGroup using Java Code?
>> Thanks in advance.
>>
>
> It's the same thing as programatically adding an object to a page and
> setting its properties. In velocity you would do:
>
> #set($allgroupdoc = $xwiki.getDocument('XWiki.XWikiAllGroup'))
> #set($newuseringroup = $doc.getObject('XWiki.XWikiGroups', true))
No, that's wrong, getObject will return an existing object, which means
that it will replace an existing member with the new one.
XWikiDocument doc = xwiki.getDocument("XWiki.XWikiAllGroup", context);
if (doc.getObject("XWiki.XWikiGroups", "member", userDocName) == null) {
BaseObject obj = doc.newObject("XWiki.XWikiGroups"));
obj.set("member", userDocName, context);
xwiki.save(doc, context);
}
> $newuseringroup.set('member', 'XWiki.UserName')
> $allgroupdoc.save()
>
> Or something similar.
>
> Guillaume
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users