How to map all requests to a controller go to one method and access the original parameter

753 Views Asked by At

I have a controller where I'm trying to set defaults based on the url - but have all of the requests going to one controller. Trying to extend the answer in : URLMapping to direct all request to a single controller/action

I did this in URLMappings.groovy

"/**"(controller:"lab", action:"index", params:[labName:action])

Where I was hoping I could add the original action name to the parameters, but this doesn't seem to do anything.

Any way I could have all the requests going to that controller mapped to one action, and see what the original action name would be?

1

There are 1 best solutions below

3
On

Action name is decided based on the url mapping not by the requested url. As you are using a single action, you will always get the action name as index. Based on your requirement below are some of the options that you can choose:

  • Use requested url and http method to find the right controller and action. Not recommended.
  • Use filter for setting default data
  • Use filter to redirect to the default controller after saving the original controller and action in request attributes. Not recommended as it will cause multiple redirects
  • Extend your controllers with the default controller and do the data setting in interceptor.