mercredi 27 janvier 2016

Spring JSP Checkboxes on List Object

I am trying to use the <checkboxes> tag on a List Object. But despite reading the mykong tutorial and searching elsewhere, i can't figure out how that is done.

So here is what i want to do: I have a class like

 class Person{

    List<IceCreams> creams;

    }

So now i want to give my User a form where he can choose which IceCreams he likes.

Controller:

@Controller
public class IceCreamController{

@RequestMapping(value="icecream", method=RequestMethod.GET)
public String showPage(Model model){
Person person = repository.getPerson(); //Returns a Person, "creams" is not empty
model.addAttribute("creams", person.getIceCreams();
}

@RequestMapping(value="icecream", method=RequestMethod.POST)
public String showPage( @ModelAttribute("teilnehmer") List<IceCreams> likedCreams, Model model){
//do something with selected iceCreams
}

Now i don't understand how to continue in the JSP. I know i have to use the checkboxes tag, but i do not know what it returns on submit or if i use it correctly.

<form:form>
<form:checkboxes path="creams" items="${creams}"/>
<input type="Submit" value="Submit">
</form:form>

So the question is: What do i write in the JSP and what will be returned to the controller? Thank you!




Aucun commentaire:

Enregistrer un commentaire