This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

How to map all request params to one object? Needed additional mechanismPage Title Module

How to map all request params to one object? Needed additional mechanism

Oct 27th, 2011, 02:43 AM

Hello!

I'm new to Spring but I try to use it in my little project. Here is my situation:
On my form you can view and add number of Tasks that user is assigned. Task has:
project name - combobox
task name - combobox
7xday input felds - text input fields for inputing hours spend on task each day of week.

You can add new tasks by clicking "add" button which uses jQuery to generate new table row with task fields described above.

I do not know how many tasks there will be when form is submitted to field names for each tasks have a name pattern:
var task_num=0; <=at begining

So I have a class AssignedTask that holds:
Project
Task
User
Day[] <=array of days

I'm using annotated controller and I would like to achieve something like:

Code:

@controller
@RequestMapping("/tasks")
public class TasksController{
@RequestMapping
public ModelAndView saveTasks(List<AssignedTask> tasks){
//Or instead of list I can use some Object that would
//hold the list of AssignedTasks
...
}
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(AssignedTask.class, new AssignedTaskEditor());
}
}

I have read aboute @InitBinder and I thought I could use it but It didnt work

I would be veeeeery gratefull for any hints or code samples on how to Bind a structure of request params to complex model structure i have.