0

I have a relationship like below

USER       USER-SKILL     SKILL
id         userid         id
title      skillid        title
           level

How u see I need add some skills for user (and put data to extra field "level"), for simplicity we assume that we create a new user and add existing skills.

So what i do:

Controller

@RequestMapping(value = "insterpage", method = RequestMethod.GET)
    public String insertPageGet(ModelMap model) {

        model.addAttribute("listAttribute", new ArrayList<UserSkill>());
        model.addAttribute("userAttribute", new User());

        return "insertpage";
}

@RequestMapping(value = "insterpage", method = RequestMethod.POST)
    public String insertPagePost(ModelMap model, @ModelAttribute("userAttribute") User user, @ModelAttribute("listAttribute") List<UserSkill> userskill) {

        user.setUserSkills(list); // all the details of the assignment skills to user i skipped here, because it is not important here
        userService.insert(user);

        return "userlist";
}

JSP page

<form:form modelAttribute="userAttribute">
   <form:label path="title">Title</form:label>
   <form:input path="title"/>
</form:form>

<form:form modelAttribute="listAttribute">
   <!-- loop here, i want insert 10 times different skills -->
   <form:label path="level">Level</form:label>
   <form:input path="level"/>
   <form:hidden path="skill" value="{skill.id}">
</form:form>

<input type="submit" value="Submit">

Although the two forms, using jQuery (function serialize()) i can send attributes to controller. I wonder more how to send multiple objects and put in the list as above.

How do I deal with this? Any ideas?

user2363971
  • 191
  • 1
  • 4
  • 19

0 Answers0