With this interceptor you can intercept local event actions and execute things before the requested action executes. You can do it globally by using the preHandler()
method or targeted to a specific action pre{actionName}()
.
// executes before any action
function preHandler( event, action, eventArguments, rc, prc ){
}
// executes before the list() action ONLY
function preList( event, action, eventArguments, rc, prc ){
}
// concrete example
function preHandler( event, action, eventArguments, rc, prc ){
if( !security.isLoggedIn() ){
event.overrideEvent( 'security.login' );
log.info( "Unauthorized accessed detected!", getHTTPRequestData() );
}
}
function preList event, action, eventArguments, rc, prc ){
log.info("Starting executing the list action");
}
The arguments received by these interceptors are:
event
: The request context referenceaction
: The action name that was interceptedeventArguments
: The struct of extra arguments sent to an action if executed viarunEvent()
rc
: The RC referenceprc
: The PRC Reference
Here are a few options for altering the default event execution:
- Use
event.overrideEvent('myHandler.myAction')
to execute a different event than the default. - Use
event.noExecution()
to halt execution of the current event
See the RequestContext documentation for more details.
You can fine tune these interception methods by leveraging two public properties in the handler:
this.prehandler_only
: A list of actions thatpreHandler()
will ONLY fire onthis.prehandler_except
: A list of actions thatpreHandler()
will NOT fire on
// only fire for the actions: save(), delete()
this.prehandler_only = "save,delete";
// DO NOT fire for the actions: login(), doLogin(), logout()
this.prehandler_except = "login,doLogin,logout"