1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.web.servlet.mvc.throwaway;
  17. import org.springframework.web.servlet.ModelAndView;
  18. /**
  19. * ThrowawayController is an alternative to Spring's default Controller interface,
  20. * for executable per-request command instances that are not aware of the Servlet API.
  21. * In contrast to Controller, implementing beans are not supposed to be defined as
  22. * Servlet/Struts-style singletons that process a HttpServletRequest but rather as
  23. * WebWork/Maverick-style prototypes that get populated with request parameters,
  24. * executed to determine a view, and thrown away afterwards.
  25. *
  26. * <p>The main advantage of this controller programming model is that controllers
  27. * are testable without HttpServletRequest/HttpServletResponse mocks, just like
  28. * WebWork actions. They are still web UI workflow controllers: Spring does not
  29. * aim for the arguably hard-to-achieve reusability of such controllers in non-web
  30. * environments, as XWork does (the generic command framework from WebWork2)
  31. * but just for ease of testing.
  32. *
  33. * <p>A ThrowawayController differs from the command notion of Base- respectively
  34. * AbstractCommandController in that a ThrowawayController is an <i>executable</i>
  35. * command that contains workflow logic to determine the next view to render,
  36. * while BaseCommandController treats commands as plain parameter holders.
  37. *
  38. * <p>If binding request parameters to this controller fails, a fatal BindException
  39. * will be thrown.
  40. *
  41. * <p>If you need access to the HttpServletRequest and/or HttpServletResponse,
  42. * consider implementing Controller or deriving from AbstractCommandController.
  43. * ThrowawayController is specifically intended for controllers that are not aware
  44. * of the Servlet API at all. Accordingly, if you need to handle session form objects
  45. * or even wizard forms, consider the corresponding Controller subclasses.
  46. *
  47. * @author Juergen Hoeller
  48. * @since 08.12.2003
  49. * @see org.springframework.web.servlet.mvc.Controller
  50. * @see org.springframework.web.servlet.mvc.AbstractCommandController
  51. */
  52. public interface ThrowawayController {
  53. /**
  54. * Execute this controller according to its bean properties.
  55. * Gets invoked after a new instance of the controller has been populated with request
  56. * parameters. Is supposed to return a ModelAndView in any case, as it is not able to
  57. * generate a response itself.
  58. * @return a ModelAndView to render
  59. * @throws Exception in case of errors
  60. */
  61. ModelAndView execute() throws Exception;
  62. }