getting groups names in a dropdown | Community
Skip to main content
uniqeeee
October 16, 2015
Solved

getting groups names in a dropdown

  • October 16, 2015
  • 3 replies
  • 1519 views

Hi All,

 

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

PLease help

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Peter_Puzanovs

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

3 replies

Level 8
October 16, 2015

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. 

Peter_Puzanovs
Community Advisor
Peter_PuzanovsCommunity AdvisorAccepted solution
Community Advisor
October 16, 2015

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

Ojjis
Level 7
October 16, 2015

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-and-sling.html

Good Luck
/Johan