I have a simple Role class which has a List<Authority>
Then I have a JSP which allows me to edit roles and their properties:Code:@Entity @Table(name="role") public class Role implements RoleInterface { (...) private List<Authority> authorities; (...) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name = "role_x_authority", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "authority_id") }) public List<Authority> getAuthorities() { return authorities; } public void setAuthorities(List<Authority> authorities) { this.authorities = authorities; }
${authorityList} above is a full list of all available authorities. I want the ones that are already attached to the Role object to be checked. However, nothing is checked. Saving works properly.HTML Code:<form:form method="post" modelAttribute="role"> <form:errors path="*" cssClass="error" /> <table> <tr> <td>${role.id } - Role Id</td> <td><form:input disabled="true" path="id" /></td> </tr> <tr> <td>Role Name</td> <td><form:input path="name" /></td> <td><form:errors path="name" cssClass="error" /></td> </tr> <tr> <td>Role Desc</td> <td><form:input path="description" /></td> <td><form:errors path="description" cssClass="error" /></td> </tr> <tr> <td>Authorities</td> <td><form:checkboxes items="${authorityList}" path="authorities" itemLabel="name" itemValue="id" delimiter="<br/>" /></td> <td><form:errors path="authorities" cssClass="error" /></td> </tr> <tr> <td> </td> <td><input type="submit" value="Save Role" /></td> <td> </td> </tr> </table> </form:form>
I have the following PropertyEditor
What am I missing here?Code:public class RoleAuthoritiesEditor extends PropertyEditorSupport { (...) @Override public String getAsText(){ Authority authority = (Authority) this.getValue(); String textVal = authority.getId().toString(); return textVal; } @Override public void setAsText(String text) throws IllegalArgumentException { Long authorityId = Long.parseLong(text); Authority auth = _userMgmtService.getAuthorityById(authorityId); setValue(auth); } }


Reply With Quote