4

Can we define 2 different actions in 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 the 'trimParams' action to interceptor along with 'debug' action? I do not know the exact syntax of this. Thank you so much.

Đinh Hồng Châu
  • 5,300
  • 15
  • 53
  • 90

1 Answers1

3

I suggest you defining a separate action for the 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 it, but it might help.

elCapitano
  • 1,821
  • 3
  • 22
  • 42