[英]Separately managing obiects from lists in spring 3 mvc + jsp web application
After thinking a lot, this is the best question title I could find. 经过多番思考,这是我能找到的最佳问题标题。 Not that representative, I'm sorry :-(.
不是那个代表,对不起:-(。
By the way let me explain the problem. 顺便说一下,让我解释一下这个问题。 I have to implement an administration panel.
我必须实现一个管理面板。 It displays a table where every line contains a user with his roles and account status.
它显示一个表格,其中每一行都包含一个用户及其角色和帐户状态。 You can see the idea sketched in the following image
您可以在下图中看到素描的想法
now, my problem is about managing the backing model object: 现在,我的问题是关于管理支持模型对象的:
I found many tips for managing the table as a whole so that a single button submits all the users at the same time, but what I want to do is populating the table with a list and managing every list record (the user) separately . 我发现了很多技巧来管理该表作为一个整体,这样一个单一的按钮提交所有用户在同一时间,但我想要做的是与列表填充表, 单独管理每一个列表记录(用户)。
I thought to manage each line with javascript to keep trace of the modified values and to use them to build a uri like http://authority/app/user_management/{user_id}/{is_locked}/{is_admin}/.../
. 我想用javascript管理每一行,以跟踪修改后的值,并使用它们来构建uri,例如
http://authority/app/user_management/{user_id}/{is_locked}/{is_admin}/.../
。 The uri will be triggered by the corresponding submit button, but I prefer to avoid this approach. uri将由相应的“提交”按钮触发,但是我更喜欢避免这种方法。
Moreover, to populate the table with the correct checkbox value it is necessary to have a binding enstablished. 此外,要使用正确的复选框值填充表,必须设置绑定。 Any advice?
有什么建议吗? Thanks!
谢谢!
I think you can use separate form for each row with a User object as a Model. 我认为您可以使用User对象作为模型为每一行使用单独的表单 。 You will have simple 'updateUser' handler with User object in input parameters list.
您将在输入参数列表中具有带用户对象的简单'updateUser'处理程序。 As I remember it could be a User you are iterating through in your foreach, but I need to check it with the real example..) At least you can use simple form and pass 'id', 'isLocked', etc. as request parameters.
我记得它可能是一个用户,您正在foreach中进行迭代,但是我需要用真实的示例进行检查。.)至少您可以使用简单的表单并按要求传递“ id”,“ isLocked”等参数。
<!-- Inside foreach loop -->
<form action="/updateUser" method="POST">
<input type="hidden" name="id" value="${user.id}"/>
<tr>
<td><input type="checkbox" name="isAdmin" value="Is Admin" checked="${user.isAdmin}"/></td>
<td><input type="submit" value="Submit"/></td>
</tr>
</form>
And something similar on server side: 和服务器端类似的东西:
@RequestMapping(value = "/updateUser", method = RequestMethod.POST)
@ResponseBody
public ResponseDTO updateUser(@RequestParam String id, @RequstParam boolean isAdmin) {
// your update logic
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.