开发者

spring portlet mvc: model attribute is null despite being modelAttribute?

In my rendermapping I put a User object in my model(model.addAttribute). In the coupled JSP I do:

<form:form action="x" method="post" modelAttribute="user">
Username: ${user.username}
Age: ${age}
This information is correct: <input type="checkbox" id="correctInformation"/>
<input type="submit" value="Submit"/>
<开发者_如何转开发/form:form>

However in the method mathing x when I retrieve the user object using an @ModelAttribute tag the user object is a new instance instead of the one used in the form (the username is empty etc).

Does anyone know why this happens and the solution?

edit: I can use <input type:hidden path="username"/> and it works but that isn't really that clean... Is there a better solution?


The problem is the same as the other question. You are not sending the information in the form unless you add a form tag for the fields. So the usual way to go is to add a hidden field to send this information like this:

with spring tags:

<form:hidden path="username" />

or just with a form tag

<input type="hidden" name="username" value=" ${user.username}" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜