Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Restrict Page Creation Based on Condition


Community Advisor

I have a requirement to restrict page creation based on some conditions.

For Example,
When an author wants to create a page I need to check some validity from my Java code


As soon as I found anything wrong I need to restrict the author from creating the page and show some error. (This error could be the exception message).


For this, I tried implementing EventListener, but Event is triggered after the page creation.

public JackrabbitEventFilter createPageEvent (String path) {
        JackrabbitEventFilter jackrabbitEventFilterPage = new JackrabbitEventFilter();

        return jackrabbitEventFilterPage.setAbsPath(path)
                .setNodeTypes(new String[]{NT_PAGE, NT_TAG});

In the OnEvent I throw an exception,

public void onEvent(EventIterator events) {
    throw new AccessControlException("Restricted");
    // Or any kind of exception

But this is not working. 

How I can achieve this?
Note: I also need to get the page properties that are filled up by the author.

2 Replies


Community Advisor

@Sady_Rifat :Instead of writing the event listener .Can you try below. 


in the create page wizard, the below validation happens from the below validations.js file . You can write your validation in the below JS file.


JS file location: /libs/cq/gui/components/siteadmin/admin/clientlibs/validations/js/validations.js





SO its better to overlay and customize this js file instead of writing event listener.




Community Advisor

Using clientlib is possible. But the requirement is to use Java directly. If it's not possible to solve by Java directly then I will go for the clientlib solution.