Announcement Announcement Module
No announcement yet.
Two FormController share the same view Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Two FormController share the same view

    I am using Spring MVC.

    I have two FormControllers, which share the same FormView (a jsp file named GeneralForm.jsp. The view name is "GeneralForm"). One controller is mapped with URL "/action/a", the other with "/action/b".

    The question is, how do I know which controller is requesting "GeneralForm" view in the jsp page? If I try anything like ${pageContext.request.requestURI}, it will only returns me the jsp page's path, which is GeneralForm.jsp.

    Is there a way to get the controller information in the JSP page?

    Or, can I specify something in the appicationContext so that I can pass a parameter (such as controller id) when the controller is calling FormView?



  • #2
    An ad hoc way I use in those case is to add in the model the "mode" or reason which made this view called (e.g. "creation" mode or "edition" mode or "display" mode). This way you don't need to synchronize your url mapping and view content (since it needs to know the urls, which is bad imho), but you refer to a more abstract reference, which is this "mode" and makes the view more maintenable.