I have ...
- a
Seq[RoleId]defining all roles that a user can get granted - a
Userwith a propertyroles: Seq[RoleId], where the roles are those that the user has got granted - a Play controller preparing a form and providing the user (including her roles) and the Seq of available RoleIds to the html page as part of the form's data (including the mapping)
- a Twirl template showing a checkbox for each available role
What I'd like to achieve is a list of checkboxes where every checkbox who's value is part of the user's roles is checked. So the list should show which of the available roles are granted to the user, as shown in this very refined prototype:
Name: [Doe, John]
Roles: [ ] Admin
[x] Manager
[x] Service Desk
[ ] Jack of all trades
if the user's name is John Doe with the roles Manager and Service Desk.
That seems rather simple, but I can't find a way to achieve it without some hacks (like circumventing the form and moving the role date to the Twirl template as a regular parameter; writing a custom mapper in the form handling code etc.). Isn't there a way to do it in the Play way without all that boilerplate ?
I googled hard, but I couldn't find any example that seemed to do it right. And Play's form processing docs weren't helpful either.
Any ideas ?