spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
55.49k stars 37.71k forks source link

introduce @RequestAttribute [SPR-4271] #8949

Closed spring-projects-issues closed 15 years ago

spring-projects-issues commented 16 years ago

allnightlong opened SPR-4271 and commented

My project have meaningfull url strategy i.e. it looks like: example.org/user/1234/ instead of example/?user=1234. I've got filter wich redirects each request to DispatcherServlet and put id (1234) in request as attribute. But i can't access to this attributes throw annotation-based controller in a way I can access request parameters. So I think introducing @RequestAttribute is a decision:

public void showUser(@RequestAttribute in userId){ ... }


Affects: 2.5 final

spring-projects-issues commented 15 years ago

Robert Varga commented

This is one side of the problem. The other side is that you should not have the filter, Spring should support binding the path segment to a method parameter.

spring-projects-issues commented 15 years ago

Nic H commented

The user isn't necessarily in the request path. A common scenario is where a Filter gets the user out of the current session (via cookies, DB) and places an object for it in a request attribute. In an annotation-driven controller, it's hard to get this user out without resorting to singletons or exposing the request object.

spring-projects-issues commented 15 years ago

Juergen Hoeller commented

We don't plan on introducing such attribute access annotations. Instead, in Spring 3.0, we have an @PathVariable annotation (for extracting URI template parameters) and a general @Value annotation (for resolving EL expressions, which also allows for dereferencing request and session context data). This should cover all remaining cases quite nicely.

Juergen

spring-projects-issues commented 15 years ago

Nic H commented

Cool - we were planning to upgrade to 3.0 anyway :)