Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do model attributes get stored?

I searched a lot and can't find an answer.

Where the model object values are stored in Spring .

Where the model.addAttributes("key","values") values are stored (eg : session , request).What is the scope of the this?

How I can get the values of the stored value in the JSP using the expression language like ${key} ?

How the EL works to retrieve the stored values in the model?

like image 908
Human Being Avatar asked Jan 08 '14 15:01

Human Being


2 Answers

The DispatcherServlet, which is the entry point of any Spring MVC application, creates a new ModelAndViewContainer object on each request. The javadoc for this class states

Records model and view related decisions made by HandlerMethodArgumentResolvers and HandlerMethodReturnValueHandlers during the course of invocation of a controller method.

Those two interfaces are what handles resolving your @RequestMapping annotated method arguments and return values.

So, during the lifecycle of the request, the model attributes are stored in a ModelMap field of this ModelAndViewContainer object. The actual, current, implementation is a BindingAwareModelMap.

Towards the end of the request, when a view needs to be rendered, some View objects will merge the model attributes with the HttpServletRequest attributes.

How the EL works to retrieve the stored values in the model?

It doesn't. EL resolves the attributes from the JSP's page scope,HttpServletRequest, HttpSession, or ServletContext.

like image 171
Sotirios Delimanolis Avatar answered Sep 22 '22 07:09

Sotirios Delimanolis


It's in the request, unless modified with a @SessionAttributes. If you're doing a redirect--request attributes are lost; it's a new request.
For your second and third question are addressed by this link Where does the Spring Model that is passed to a JSP goes to?

like image 34
Pradeep Kr Kaushal Avatar answered Sep 23 '22 07:09

Pradeep Kr Kaushal