Question

I have a problem with transferring an object (as a modelAttribute) and its values in a form between controllers. I have a form with modelAttribute, say "myObject", which has some members. I add a modelAttribute "myObject" to model in the first controller.

I am able to read and present values of "myObject" values in the view, for example, I can get values via ${myObject.memberName}, but when it comes to the second controller which takes as a parameter the object (I mean: modelAttribute("myObject") MyObject myObject) the members are set to default values, mainly null!

Some values are being set in the form (they work fine) and rest of them are being set in the first controller. I want to get values set in the first controller in the second one but they are lost.

How should I transfer the values of a modelAttribute object to not lost them between controllers? Should I place them in HttpRequest paratemers?

Était-ce utile?

La solution

HTTP is a stateless protocol. So you can expect that parameters are not going to hang around between requests.

Should I place them in HttpRequest paratemers?

Yes, if you want the values to be available to the controller which handles the next request you need to pass them as part of the request/post them in some form data.

If you have data which you wish to make available to many requests you could consider putting the model in the HttpSession.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top