views:

72

answers:

1

I have a web-application in spring where tasks should be assigned to workers (say programmers).

  1. the application should be able to list tasks (unassigned tasks) in a grid
  2. On another side, the application should list workers (say programmers)
  3. the manager should be able to choose select tasks (or checking), and choose workers to whom he/she wishes to assign selected tasks
  4. 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 another for tasks). I appreciate any idea, link to a resource or a link to the same question as mine.

+1  A: 

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;

    ...
}
axtavt
Thanks axtavt for the answer, if i got it well, you are suggesting to have an array of objects in such a way <code> MyController extends SimpleFormController {...private Task[] tasks; private Worker[] workers; ... IOC stuff goes here ......some other methods ...@override public void onSubmit( Command command ) { ... /*I am dealing with 2 kind of objects and my problem is here */ NewModelManyToManyObjectGoesHere wotgfc = (NewModelManyToManyObjectGoesHere) command;// ... } }</code> Thanks very much I will try it out, thanks again.
P.M