views:

26

answers:

2

Hi All,

We are using dotCMS 1.7a and I am having difficulty getting the email addresses of users in the Administrator role.

This SQL works:

   select user_.emailaddress
   from user_
   INNER JOIN users_roles
   ON users_roles.userid = user_.userid
   INNER JOIN role_
   ON users_roles.roleid = role_.roleid
   where role_.name = 'Administrator';

But this Velocity code doesn't:

   <p>Start</p>
   #set($found = $cmsuser.searchUsersAndUsersProxy(null, null, null, [], true,
   ["Administrator"], true, null, 1, 0))
   <p>Finish</p>
   <p>Found: $found [$found.size()].</p>
   #set($theUsers = $found.get("users"))
   <p>Got theUsers: $theUsers [$theUsers.size()].</p>

The output of the above code is:

   Start
   Finish
   Found: {total=22, usersProxy=[], users=[], groupNames=[], roleNames=[]} [5].
   Got theUsers: [] [0].

What is going wrong? Any help would be most appreciated!

Rob :)

A: 

I don't know anything about this cms, but I think velocity doesn't like those parameters you pass. Velocity doesn't have "null" concept, and those inline arrays are probably not welcome either.

I think you need to get those users on a server side and then pass ready to display objects to velocity. That's kind of what a templating engine is for - to display the data, not to retrieve it.

serg
Thanks for the answer Serg. I will try writing those parameters in a different way.
Robert Mark Bram
Regarding your second thought, dotCMS is structured so that logic can be embodied within pages easily without a "backend". They exposed APIs through Velocity just for this purpose. Their tagline (dotcms.com) facetiously underlines this: "Look Ma, No Application Developers Required." Yeah right. Having said that, I think the above logic is not so serious that it needs to be separated.
Robert Mark Bram
This is definitely the format accepted for arrays. (http://velocity.apache.org/engine/releases/velocity-1.5/vtl-reference-guide.html) #set( $monkey.Say = ["Not", $my, "fault"] )
Robert Mark Bram
@Robert As far as I know arrays are backed by ArrayList in velocity, so when you create an array and pass it as a parameter it would probably pass ArrayList, not array. I think you can just set a breakpoint in your methods and see what's going on.
serg
A: 

Got the answer - thanks to Paul P. :)

#set($found = $cmsuser.searchUsersAndUsersProxy(null, null, null, [], false,
["Administrator"], true, null, 1, 1000))
<p>Found $found.get("users").size() Administrator users.</p>
#set($theUsers = $found.get("users"))
#foreach ($user in $theUsers)
$user.fullName ($user.emailAddress)<br>
#end

Note 1. Javadocs for $cmsuser.searchUsersAndUsersProxy() show the parameters for that method.

Note 2. In this case (dotCMS 1.7) the pageSize arg (final int - number of element to show in the page) doesn't follow dotCMS convention i.e. 0 really does mean 0! Normally it means "no limit".

Note 3. The fifth parameter (showUserGroups) should be false or I will get duplicates (as in a full join).

Robert Mark Bram