Spring Framework
  1. Spring Framework
  2. SPR-5779

Add "controller class name" attribute to spring:url and form:form tags

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0 M3
    • Fix Version/s: 4.1 RC1
    • Component/s: Web
    • Labels:
      None

      Description

      The various Spring Web tags and template-URI implementation encourage hard-coding of URLs in the view layer.
      If I alter a Controller's URL mapping, I need to remember to go and make the corresponding change(s) in my JSPs so that links and forms aren't broken.
      If the spring:url and form:form tags were able to accept the FQCN of a controller bean instead of an actual URL, the tag implementation could determine the most appropriate URL mapping, and (if applicable) incorporate any template-URI params / path variables to generate a reliable URL.
      By using the the FQCN, we can rely on any modern IDE to locate references during refactoring, instead of requiring additional help from Spring-aware IDE plugins. IMHO this would fit particularly well with Spring 3.0's annotation-based controller configuration.

      Stripes supports this approach:
      http://stripes.sourceforge.net/docs/current/taglib/stripes/link.html
      http://stripes.sourceforge.net/docs/current/taglib/stripes/form.html

        Issue Links

          Activity

          Hide
          Alexander Hawley added a comment - - edited

          Asp.Net implementation might be workable.

          Many MVC frameworks generate URIs from controller mappings. It closes the loop on referencing a controller action from anywhere: a redirect from controller to controller, link from a view to controller, submit form from view to controller. They can all reference the resource map in the same way.

          Show
          Alexander Hawley added a comment - - edited Asp.Net implementation might be workable. Many MVC frameworks generate URIs from controller mappings. It closes the loop on referencing a controller action from anywhere: a redirect from controller to controller, link from a view to controller, submit form from view to controller. They can all reference the resource map in the same way.
          Hide
          Andy Chang added a comment - - edited

          We have been using a form of this internally @ mohchi.com, but it requires a separate annotation (@Action). It supports path variables but perhaps not in the way you'd like it to. It uses an action uri builder to build urls in the view layer. I hope that some elements from our example might help in integrating this functionality into spring:url and @RequestMapping.

          The controller:
          https://github.com/mohchi/spring-mvc-action-resolver/blob/master/src/main/java/com/mohchi/example/web/controllers/HomePageController.java

          The jsp:
          https://github.com/mohchi/spring-mvc-action-resolver/blob/master/src/main/webapp/WEB-INF/views/homePage.jsp

          That the JSP doesn't have any examples of this, but it also supports fully qualified names, e.g. "com.mohchi.example.web.controller.HomePageController#homePage". However, one limitation is that it doesn't support overloaded controller methods annotated with @Action.

          Show
          Andy Chang added a comment - - edited We have been using a form of this internally @ mohchi.com, but it requires a separate annotation (@Action). It supports path variables but perhaps not in the way you'd like it to. It uses an action uri builder to build urls in the view layer. I hope that some elements from our example might help in integrating this functionality into spring:url and @RequestMapping. The controller: https://github.com/mohchi/spring-mvc-action-resolver/blob/master/src/main/java/com/mohchi/example/web/controllers/HomePageController.java The jsp: https://github.com/mohchi/spring-mvc-action-resolver/blob/master/src/main/webapp/WEB-INF/views/homePage.jsp That the JSP doesn't have any examples of this, but it also supports fully qualified names, e.g. "com.mohchi.example.web.controller.HomePageController#homePage". However, one limitation is that it doesn't support overloaded controller methods annotated with @Action.
          Hide
          Fabien benichou added a comment -

          It is à shame that such a popular MVC framework like Spring does not have this mechanism present in many other frameworks (like Grails) and forces you to hardcode your URLs in your code

          Why this feature is not a top priority for future releases ?

          Show
          Fabien benichou added a comment - It is à shame that such a popular MVC framework like Spring does not have this mechanism present in many other frameworks (like Grails) and forces you to hardcode your URLs in your code Why this feature is not a top priority for future releases ?
          Hide
          Juergen Hoeller added a comment -

          Let's put this into the 4.1 bucket to consider potential mechanisms in Spring MVC itself, or at least some enablers for custom policies to be implemented on top of it.

          Juergen

          Show
          Juergen Hoeller added a comment - Let's put this into the 4.1 bucket to consider potential mechanisms in Spring MVC itself, or at least some enablers for custom policies to be implemented on top of it. Juergen
          Hide
          Rossen Stoyanchev added a comment - - edited

          Now that we have MvcUriComponentsBuilder, this is a good one to consider. For example based on the fromMethodName method.

          Show
          Rossen Stoyanchev added a comment - - edited Now that we have MvcUriComponentsBuilder, this is a good one to consider. For example based on the fromMethodName method.

            People

            • Assignee:
              Rossen Stoyanchev
              Reporter:
              Chris Herron
              Last updater:
              Rossen Stoyanchev
            • Votes:
              32 Vote for this issue
              Watchers:
              26 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since last comment:
                14 weeks, 5 days ago