Respond to a Page Create, Copy, Move, Delete, or Update Event
Overview
You can extend the page create, copy, move, delete, or update process in Bloomreach Content by adding custom logic. This allows you to trigger additional behavior when users perform page actions in the Experience manager.
When to Use
Implement a custom response to page actions when you need to:
- Trigger workflows or integrations on page creation, copy, move, deletion, or update
- Enforce business rules before changes are persisted
- Abort the action based on custom validation
- Perform cleanup or notifications related to page actions
How Page Action Events Work
When a user initiates a page action (create, copy, move, delete, or update) through Page Settings, the delivery tier (HST) sends a PageEvent to its synchronous internal event bus before persisting changes to the repository. The event type matches the action performed.
You can register a listener for these events to implement custom logic. The event context, available through the PageEvent’s getPageActionContext method, provides details about the action. You can also abort the action from within your listener if necessary.
Important:
Do not save the JCR session accessed through the event context. The delivery tier manages session persistence after event processing. Saving the session in your listener can cause data integrity issues.
Access to the JCR session is available via:
pageEvent.getPageActionContext().getRequestContext().getSession();
or, for example, in a PageCopyEvent:
copyEvent.getPageActionContext().getNewSiteMapItemNode().getSession()
Implementation Steps
1. Create a Custom Listener for Page Events
The following example shows how to implement a listener for PageCopyEvent. To handle other actions, use the corresponding event class (PageCreateEvent, PageMoveEvent, PageDeleteEvent, or PageUpdateEvent). Each event type exposes different context information through its specific PageActionContext implementation. Refer to the JavaDocs API Documentation for details on PageCreateContext, PageCopyContext, PageMoveContext, PageDeleteContext, and PageUpdateContext.
package com.example.pagecopy; import org.hippoecm.hst.pagecomposer.jaxrs.api.ChannelEventListenerRegistry; import org.hippoecm.hst.pagecomposer.jaxrs.api.PageCopyEvent; import org.onehippo.cms7.services.eventbus.Subscribe; public class PageCopyEventListener { @SuppressWarnings("UnusedDeclaration") public void init() { ChannelEventListenerRegistry.get().register(this); } @SuppressWarnings("UnusedDeclaration") public void destroy() { ChannelEventListenerRegistry.get().unregister(this); } @Subscribe public void onPageEvent(PageCopyEvent event) { if (event.getException() != null) { return; } // Implement custom logic here. // Do not save the JCR session obtained from PageCopyEvent#getPageActionContext#getRequestContext. } }
2. Register the Listener as a Spring Bean
Initialize your event listener as a Spring bean. For example, add the following configuration to site/components/src/main/resources/META-INF/hst-assembly/overrides/page-event-listeners.xml:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean class="com.example.pagecopy.PageCopyEventListener" init-method="init" destroy-method="destroy"/> </beans>
After configuration, the onPageEvent method is called before any changes are persisted when a user copies a page through Page Settings.
Abort a Page Action from a Listener
You can abort a page action by setting an exception on the event object in your listener. Use this approach to enforce requirements or handle post-processing failures. For more information, see Abort an Experience Manager Action.
Verification
- Trigger the relevant page action in the Experience manager.
- Confirm that your custom logic executes as expected.
- Verify that the action is aborted if your listener sets an exception.