Grails beforeInterceptor with two actions

Can we define 2 different actions in the beforeInterceptor of a Grails controller? I have a controller with below beforeInterceptor:

def beforeInterceptor = [action:this.&debug]

def trimParams() {
    params?.each { it = it.toString().trim() }
}
def debug() {
    log.info("${actionUri} with params ${params}")
}

How can I add a trimParams action for an interceptor along with a debug action? I do not know the exact syntax for this. Thank you very much.

+3
source share
1 answer

I suggest you define a separate action for an interceptor:

def beforeInterceptor = [action:this.&doBeforeStuff]

def doBeforeStuff() {
    trimParams(params)
    debug(params)
}

def trimParams() {
    params?.each { it = it.toString().trim() }
}
def debug() {
    log.info("${actionUri} with params ${params}")
}

I have not tried but can help.

+3
source

All Articles