How to implement filter for index action

Posted By : Shiv Kumar | 15-Oct-2014
Sometimes we have to do some pre-processing before request intercepts and post-processing after request process. We use filters for that as they are also easily manageable by plugin. Syntax to define filter :
def filters = { testFilter(controller: 'test', action: '*') { before = { if (actionName.equals('update')) { // do something } after = { Map model -> } } } }
It is easy to apply filter any action and controller.But for default action "index",this won't work :
filterForIndex(controller: 'test', action: 'index') { before = { // do something } } filterForIndex(controller: 'test', action: 'null') { before = { // do something } }
If you log actionName in action "index" like :
log.debug"actionName == "+actionName // it will give null
Now do whatever you want in filter for index action. Thanks Shiv Kumar

About Author

Author Image
Shiv Kumar

Shiv is an experienced Java Developer with a strong background in multiple technologies. He specializes in defining system architectures to ensure reliable and resilient solutions. He possesses a comprehensive understanding of the latest technologies and has hands-on experience in Core Java, Spring Boot, Hibernate, Apache Kafka messaging queue, Redis, as well as relational databases like MySQL and PostgreSQL, and non-relational databases like MongoDB. He excels in API implementations, Microservices, Web Services development, testing, and deployments. Shiv actively contributes to code enhancements and consistently delivers valuable contributions to various client projects, including Fabtrack, Pando, Pandojo, Digikam, WhatsApp Integration, Croniz, Punchin Application, Script TV, Bhaasha, and more. He demonstrates strong analytical skills and a creative mindset. In addition, he has a passion for reading books and exploring new technologies and innovations.

Request for Proposal

Name is required

Comment is required

Sending message..