0

In a view, how would I access the name of controller and method that returned the view? This is rather straight forward in Grails, but I'm stumped on how to go about it in plain Spring.

andyb
  • 43,435
  • 12
  • 121
  • 150
vector
  • 7,334
  • 8
  • 52
  • 80

2 Answers2

2

JSP (You are using a JSP view right?) doesn't have a ${controllerName} expression like in Grails. But you can pass the name of the controller and the method via model.

lunr
  • 5,159
  • 4
  • 31
  • 47
  • thought about that one, and wondered if it can be avoided ;-) But, this might be the simplest way of handling it. – vector Jun 18 '13 at 14:04
  • Then maybe you may want to implement a `HandlerInterceptorAdapter`. I think this question may help you: http://stackoverflow.com/questions/8384903/how-to-get-controller-method-name-in-spring-interceptor-prehandle-method. Once you get the name of the controller and the method name, you can add them to the model in the `postHandle` method. – lunr Jun 18 '13 at 14:37
  • The ` HandlerInterceptor` is a bit more explained here: http://stackoverflow.com/a/21278494/280244 – Ralph Jan 22 '14 at 09:23
2

just do in controller method

String className = this.getClass().getName();

and add classname to model.

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311