I have some troubles to update Many-To-Many Relationship with checkboxes in Play Framework 2.1.0
Account Model:
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "account_security_role", joinColumns = { @JoinColumn(name = "account_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "security_role_id", referencedColumnName = "id") })
public List<SecurityRole> roles;
I want to update account roles in account edit view
Edit Account View:
@for(role <- SecurityRole.find.all()) {
<div class="control-group">
<label class="control-label"> @role.description </label>
<div class="controls">
<div class="text-toggle-button">
<input type="checkbox" name="roles[@role.id].id" value="@role.id" class="toggle"
@if(loggedAccount.hasHole(role.id)) {
CHECKED
} />
</div>
</div>
</div>
}
So, when I call Update POST
method I get this error:
InvalidPropertyException: Invalid property
roles[3]
of bean class [models.Account
]: Illegal attempt to get propertyroles
threw exception; nested exception isorg.springframework.beans.NullValueInNestedPathException
: Invalid propertyroles
of bean class [models.Account
]: Could not instantiate property type [be.objectify.deadbolt.core.models.Role
] to auto-grow nested property path:java.lang.InstantiationException
:be.objectify.deadbolt.core.models.Role
Is there some example to update a model using checkbox and Many-To-Many relationship?
Thanks a lot. Lew