Announcement Announcement Module
Collapse
No announcement yet.
How to map all request params to one object? Needed additional mechanism Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    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

    task_num++; <= at every task
    project_<task_num>
    task_<task_num>
    day_<task_num>_mon
    day_<task_num>_tue
    ... etc

    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.
Working...
X