Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-5779

Allow links to @Controller methods from views without hardcoding URLs

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • 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
          fabien7474 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
          fabien7474 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 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 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
          rstoya05-aop 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
          rstoya05-aop 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.
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment - - edited

          I've created a proposal to address this. For anyone interested, you can try it with 4.1.0.BUILD-SNAPSHOT (repo.spring.io/snapshot).

          For an overview and sample usage, see the javadoc of MvcUriComponentsBuilder.fromMappingName.

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - - edited I've created a proposal to address this. For anyone interested, you can try it with 4.1.0.BUILD-SNAPSHOT (repo.spring.io/snapshot). For an overview and sample usage, see the javadoc of MvcUriComponentsBuilder.fromMappingName .
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment -

          Modified title (was "Add "controller class name" attribute to spring:url and form:form tags")

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - Modified title (was "Add "controller class name" attribute to spring:url and form:form tags")

            People

            • Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              cherro Chris Herron
              Last updater:
              Stéphane Nicoll
            • Votes:
              32 Vote for this issue
              Watchers:
              29 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 3 weeks, 3 days ago