Pseudo-code:
class SomeController {
def myAction() {
// controler is an property passed via ctor
controller.redirect(toWhereever)
}
}
// another variant
class AnotherController {
def myAction(controller) {
// controler is an method argument
controller.redirect(toWhereever)
}
}
Any suggestions?
Edit: Because the question is a bit dry you could try to spice up your answers with some experience with the framework and what do you think is better with that approach.
Spring MVC and Grails (built ontop of spring) favour dependency injection with no inheritance whatsoever. Each controller is a class that does not extend anything. Instead you can inject other components into it (using dependency-injection). For example:
@Controller
@RequestMapping("/user")
public class UserController {
@Inject
private UserService service;
@RequestMapping("/register")
public String register(User user) {..}
}
@Controller
@RequestMapping("/orders")
public class OrderController {
@Inject
private UserController userController
}
(Although it is not a common practice to inject controllers into other controllers, you can inject any object)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With