Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Permissions: Hide/Show List Items in Dropdown

Avatar

Former Community Member

I have a component and I would like to use a dropdown menu. However, I want to hide certain options for the Author user group.

Admin should see:

  • Brown 
  • Yellow
  • Purple
  • Blue

But an author should only see:

  • Brown
  • Yellow

How can I incorporate the access controls at the script level for a specific tab inside a component?

1 Accepted Solution

Avatar

Correct answer by
Level 8

Take a look at /libs/cq/personalization/components/traits/percentile for an example of a dynamically generated  selection list. The dialog sets the options property of the select widget to be $PATH.options.json. There is a JSP that is responsible for generating the select options - /libs/cq/personalization/components/traits/percentile/options.json.jsp. So in your case your JSP would check the user's group membership and return the correct JSON based on the group membership. You could also use a OSGI Sling servlet instead of a JSP if desired. 

View solution in original post

8 Replies

Avatar

Level 10

It deponds where you are retrieving the drop down options. If the options are generating Or hard coded Or coming from external system. Then the servlet rendering the dropdown list in cq should implement the logic based on the user member to output right option.

Avatar

Former Community Member

The list options would be hardcoded. When the user makes their selection and presses OK in the component to Save, the associated action would take place. Example - Author user selects Yellow from the list (could also use radio buttons). When Author clicks Yes, the background of the header turns yellow.

Avatar

Correct answer by
Level 8

Take a look at /libs/cq/personalization/components/traits/percentile for an example of a dynamically generated  selection list. The dialog sets the options property of the select widget to be $PATH.options.json. There is a JSP that is responsible for generating the select options - /libs/cq/personalization/components/traits/percentile/options.json.jsp. So in your case your JSP would check the user's group membership and return the correct JSON based on the group membership. You could also use a OSGI Sling servlet instead of a JSP if desired. 

Avatar

Former Community Member

I don't seem to have the percentile folder under traits. Can you paste the code or is there another example?

Avatar

Level 10

which version of aem you are using?

Avatar

Former Community Member

My apologies, I'm using CQ5. (CRXDE Lite 2.3.15).

Avatar

Level 8

I think the question was 5.5 or 5.6. 

At the core what you need is code that will generate a JSON response in this format:

[
     {"value":"0-10","text":"0% - 10%"},
     {"value":"10-20","text":"10% - 20%"},
     {"value":"20-30","text":"20% - 30%"},
     {"value":"30-40","text":"30% - 40%"},
     {"value":"40-50","text":"40% - 50%"},
     {"value":"50-60","text":"50% - 60%"},
     {"value":"60-70","text":"60% - 70%"},
     {"value":"70-80","text":"70% - 80%"},
     {"value":"80-90","text":"80% - 90%"},
     {"value":"90-100","text":"90% - 100%"}
]

You can do that with either a JSP or a Servlet. Doing a selector based JSP (like putting a JSP named options.json.jsp under your component is the simplest way to accomplish this. 

Then you set your options property on your select widget to be $PATH.options.json.  

Avatar

Former Community Member

( I'm using Version 5.5 )

Ok. I'm just a beginner so some of this seems foreign but I think I have enough to play around with.

Any additional comments/alternative solutions are welcome!

I'll leave this item "open" for a few days while I try to work through it.