I am writing a small web app using servlets and JSP ( no additional frameworks ).
There is a page that displays all groups in the DB. There is a possibility to edit the entry, by pressing a button that will redirect to page "editGroup?id=1". So, the target serlvet finds to group with the provided id, populates the request with that bean and make a forward to a JSP page:
<form action="addGroup.html" method="post">
Group name : <input type="text" name="name" value="${group.name }"/><br />
Group description : <input type="text" name="description" value="${group.description }"/><br />
Group roles :
<c:forEach var="role" items="${roles}">
<input type="checkbox" name="roles_id" value="${role.id}" />${role.name}<br />
</c:forEach>
<input type="submit" value="Submit">
</form>
The question is : how to preselect the roles that already are attached to the group ?
The group’s bean has a list of beans Role. The request also has set an attribute that store the list of all available roles.
So inside of the loop I need to check if that role is already attached to the edited group.
Please help.
After some investigations I found the solution in this question:
Using expression like :
${group.roles.contains(role)}or this way (thank you, BalusC ! )