Expand my Community achievements bar.

SOLVED

getting groups names in a dropdown

Avatar

Level 1

Hi All,

 

I  have a requirement to get all groups name stored in CQ and displaying them in a dropdown.

PLease help

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Gayane,

In CQ you can retrieve groups by calling

out.print("<select>"); Iterator<Group> groups = resolver.adaptTo(UserManager.class).getGroups(); while(groups.hasNext()) { Group group = groups.next(); out.print("<option>" + group.getName() + "</option>"); } out.print("</select>");

Later in your code your could iterate through the Groups to display the neccessary information in your dropdown. resolver variable is ResourceResolver with admin permissions

Usefull links:

https://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/security/UserManager.html

https://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/security/Group.html

View solution in original post

3 Replies

Avatar

Level 8

If you are doing this is a dialog and you want to save a reference to the group you can also make use of the authselector xtype with the displayField property set to principle and the filter property set to groups. 

Avatar

Correct answer by
Community Advisor

Hi Gayane,

In CQ you can retrieve groups by calling

out.print("<select>"); Iterator<Group> groups = resolver.adaptTo(UserManager.class).getGroups(); while(groups.hasNext()) { Group group = groups.next(); out.print("<option>" + group.getName() + "</option>"); } out.print("</select>");

Later in your code your could iterate through the Groups to display the neccessary information in your dropdown. resolver variable is ResourceResolver with admin permissions

Usefull links:

https://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/security/UserManager.html

https://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/security/Group.html

Avatar

Level 7

Hi,
check this article where a list of users are fetched from CQ.
You can use the same concept but modify it to fetch groups instead.
http://blogs.adobe.com/mtg/2011/11/building-components-in-adobe-cq5-part-2-a-tutorial-on-jquery-ajax...

Good Luck
/Johan