mardi 27 octobre 2015

Unable to render checked spring checkboxes with list of object

I'm trying to render the following checkboxes checked in my view

<form:form id="mapMemberOfFormId" 
            action="${actionUrl}" 
            method="POST"
            modelAttribute="mofForm" 
            enctype="multipart/form-data"
            cssClass="cleanform">
<!-- more code -->
<form:checkboxes path="assignedRole.role.authority" items="${allAuth}" itemValue="authority" itemLabel="authority" />
<!-- more code -->
</form:form>

according to the Spring documentation if the value of assignedRole.role.authority match the value of allAuth.authority the checkbox is rendered checked.

The assigned assignedRole object is the following

@Entity
@Table(name = "ldap_memberof_role_config")
public class LDAPAuthorityEntity extends AbstractSurrogateKeyEntity{

// other fields

@ManyToOne(fetch = FetchType.EAGER, optional = false, cascade=CascadeType.ALL)
@JoinColumn(name = "role")
private AuthorityEntity role;

//other getter and setter

public AuthorityEntity getRole() {
    return role;
}

public void setRole(AuthorityEntity role) {
    this.role = role;
}

and this is the allAuth object

@Entity
@Table(name = "lookup_authority")
public class AuthorityEntity {

@Id
@Column(name = "authority")
private String authority;
//other fields

public String getAuthority() {
    return authority;
}

public void setAuthority(String authority) {
    this.authority = authority;
}

//other getter and setter

@Override
public int hashCode() {
    return this.authority.hashCode();
}

@Override
public boolean equals(Object obj) {
    if (obj == null) {
        return false;
    }
    if (! (obj instanceof AuthorityEntity)) {
        return false;
    }
    return this.authority.equals(((AuthorityEntity)obj).getAuthority());
}

but if i try to render the jsp i recive the following exception [org.hibernate.collection.internal.PersistentBag]: Bean property 'assignedRole.role.authority' is not readable or has an invalid getter method

if i change the path attribute to assignedRole.role no checkbox is checked

i tried the following to check if it's a getter/setter problems

<c:forEach items="${mofForm.assignedRole.role}" var="a">prova: ${a.authority}</c:forEach>
<c:forEach items="${allAuth}" var="a">prova2: ${a.authority}</c:forEach>

and the output, as expected, is

prova: ROLE_USER prova: ROLE_SHOW_TREE prova: ROLE_ADMIN
prova2: ROLE_ACCOUNTING prova2: ROLE_ADMIN prova2: ROLE_COMPANY_CHANGER prova2: ROLE_DARIPA_AND_DIVERSI_CC_AREA_MANAGER prova2: ROLE_FINANCE prova2: ROLE_IMPERSONATE prova2: ROLE_MANAGEMENT_AREA_DEPUTY prova2: ROLE_PAYER_1 prova2: ROLE_PAYER_2 prova2: ROLE_PLANNING_CONTROL prova2: ROLE_POST_OFFICE prova2: ROLE_PURCHASE_OFFICE prova2: ROLE_SHOW_TREE prova2: ROLE_SYS_ADMIN prova2: ROLE_TEST prova2: ROLE_USER

honestly i do not have a clue of where to look for resolving this issue. Any hints?




Aucun commentaire:

Enregistrer un commentaire