I am new to JSP, and i want to make a simple crud application. I want to save a Meal, wich consists of a number of ingredients, the problem is that you don't know how many.
I have this code within a <form action="Controller" method=POST">
.
The fault in the current code is that that HTTPServletRequest will only know that last checkbox, since all the checkboxes have the same 'name'. But as I don't know the number of ingredients the user will add i cannot number them accordingly. Is there a way to send a List to my controller ?
<%
List<Ingredient> ingredients = (List) request.getAttribute("ingredients");
%>
<div class="btn-group" data-toggle="buttons">
<% for (Ingredient ingredient : ingredients) {%>
<label class="btn btn-primary">
<input type="checkbox" name="SelectedIngredients" value="<%=ingredient.getName()%>"><%=ingredient.getName()%>
</label>
<% }%>
</div>