I am looking for a way to pre-populate a Spring MVC form from values stored in a session-scoped bean. (using this namespace: http://www.springframework.org/tags/form).
For example, say I have added a queryInfo object to the uiModel.
How do I display the name instance variable from the queryInfo object?
<form:input path="queryInfo.name" />
Is this possible? If so how?
In your request mapping, add the bean to the model:
model.addAttribute("queryInfo", queryInfo);
Then use modelAttribute in the form tag to bind it to the form:
<form:form id="some-form" modelAttribute="queryInfo">
...
Now name will display (provided there is a getter in your object appropriately named) when you do this:
<form:input path="name" />
Keep in mind form:input is a child tag of form:form. It is not meant to be used on its own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With