Add a user on a User List property

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Add a user on a User List property

Jean Couteau
Dear all,

I have a class with a UserList attribute. I am trying to add users to
this list from an other page with no success. I try using the following
code :

#if($joinTask!="")
  #set($taskDoc = $xwiki.getDocument("Project.${joinTask}"))
  #set($taskObj = $taskDoc.getObject("XWiki.TaskClass"))
  #set($list = $taskObj.get("assignedPeople"))
  $list.add($xwiki.getUser())
  $taskObj.set("assignedPeople", ${list})
  $taskDoc.save()
#end

but $list.add does not exist so I tried differently :

#if($joinTask!="")
  #set($taskDoc = $xwiki.getDocument("Project.${joinTask}"))
  #set($taskObj = $taskDoc.getObject("XWiki.TaskClass"))
  #set($list = $util.getArrayList())
  $list.add($xwiki.getUser())
  $taskObj.set("assignedPeople", ${list})
  $taskDoc.save()
#end

but I have a casting exception.

I had a look on the velocity website, on this list archives,... with no
success

My question is : Can I add users like that or the only way is through
the edit panel and if yes, what is my mistake ?

Best regards,

Jean

--
----
Jean Couteau
Code Lutin - http://www.codelutin.com
44 Bd des Pas Enchantés - 44230 St-Sébastien/Loire
Tél : 02 40 50 29 28 - Fax : 09 59 92 29 28

_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Add a user on a User List property

Jean Couteau
Any clue on this issue ?

Jean Couteau a écrit :

> Dear all,
>
> I have a class with a UserList attribute. I am trying to add users to
> this list from an other page with no success. I try using the following
> code :
>
> #if($joinTask!="")
>   #set($taskDoc = $xwiki.getDocument("Project.${joinTask}"))
>   #set($taskObj = $taskDoc.getObject("XWiki.TaskClass"))
>   #set($list = $taskObj.get("assignedPeople"))
>   $list.add($xwiki.getUser())
>   $taskObj.set("assignedPeople", ${list})
>   $taskDoc.save()
> #end
>
> but $list.add does not exist so I tried differently :
>
> #if($joinTask!="")
>   #set($taskDoc = $xwiki.getDocument("Project.${joinTask}"))
>   #set($taskObj = $taskDoc.getObject("XWiki.TaskClass"))
>   #set($list = $util.getArrayList())
>   $list.add($xwiki.getUser())
>   $taskObj.set("assignedPeople", ${list})
>   $taskDoc.save()
> #end
>
> but I have a casting exception.
>
> I had a look on the velocity website, on this list archives,... with no
> success
>
> My question is : Can I add users like that or the only way is through
> the edit panel and if yes, what is my mistake ?
>
> Best regards,
>
> Jean
>
>  


--
----
Jean Couteau
Code Lutin - http://www.codelutin.com
44 Bd des Pas Enchantés - 44230 St-Sébastien/Loire
Tél : 02 40 50 29 28 - Fax : 09 59 92 29 28

_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Add a user on a User List property

Sergiu Dumitriu-2
In reply to this post by Jean Couteau
On Mon, Feb 2, 2009 at 17:11, Jean Couteau <[hidden email]> wrote:
> Dear all,
>
> I have a class with a UserList attribute. I am trying to add users to

The UserList property is not that well maintained, and actually it
does not use a list internally. The actual data type inside is the
LargeStringProperty, which is a string (the same as TextArea). You
should instead use a DBListProperty, which is maintained and should
work as expected. The following code (and corrections) should work
with a DBList property only (also, only if Multiple select and
Relational storage are checked for the property, since otherwise you'd
also get a LargeStringProperty instead of a list).

> this list from an other page with no success. I try using the following
> code :
>
> #if($joinTask!="")
>  #set($taskDoc = $xwiki.getDocument("Project.${joinTask}"))
>  #set($taskObj = $taskDoc.getObject("XWiki.TaskClass"))
>  #set($list = $taskObj.get("assignedPeople"))

$taskObj.get doesn't return the internal value of the property, but it
actually displays the value as HTML. The right approach is:

#set($list = $taskObj.getProperty('assignedPeople').value)

Now $list is a real java ArrayList, so the next code will work.

>  $list.add($xwiki.getUser())
>  $taskObj.set("assignedPeople", ${list})

^ This is not needed, the list is already the property value. It's
enough to save the document.

>  $taskDoc.save()
> #end
>
> but $list.add does not exist so I tried differently :
>
> #if($joinTask!="")
>  #set($taskDoc = $xwiki.getDocument("Project.${joinTask}"))
>  #set($taskObj = $taskDoc.getObject("XWiki.TaskClass"))
>  #set($list = $util.getArrayList())
>  $list.add($xwiki.getUser())
>  $taskObj.set("assignedPeople", ${list})
>  $taskDoc.save()
> #end
>
> but I have a casting exception.
>
> I had a look on the velocity website, on this list archives,... with no
> success
>
> My question is : Can I add users like that or the only way is through
> the edit panel and if yes, what is my mistake ?

--
http://purl.org/net/sergiu
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users