Spring datagrid with checkboxes
I have a web-application in spring where tasks should be assigned to workers (say programmers).
- the application should be able to list tasks (unassigned tasks) in a grid
- On another side, the application should list workers (say programmers)
- the manager should be able to choose select tasks (or checking), and choose workers to whom he/she wishes to assign selected tasks
- hit submit button to assign selected tasks to chosen workers.
Now, form processing with spring is processed onSubmit(..., Command command, ...)
by binding a command (in most of cases Model classes) to the form. How can I implement the functionality above, given 2 lists (one for workers and开发者_JAVA百科 another for tasks). I appreciate any idea, link to a resource or a link to the same question as mine.
Use the fact that values of checked checkboxes with similar names can be bound as array:
<form ...>
Tasks:
<c:forEach var = "task" items = "${tasks}">
<input type = "checkbox" name = "taksIds" value = "${task.id}"> ${task.title}
</c:forEach>
Workers:
<c:forEach var = "worker" items = "${workers}">
<input type = "checkbox" name = "workerIds" value = "${worker.id}"> ${worker.name}
</c:forEach>
</form>
-
class Command {
private long[] taskIds;
private long[] workerIds;
...
}
精彩评论