Seam framework Cheat Sheets 3. selectManyCheckbox example
Example usage of selectManyCheckBoxIn this example i want to create selectManyCheckbox in order to assign a user with multiple roles. The example code is as follows
<h:selectManyCheckbox id="groups" value="#{userAccount.userRoles}" layout="pageDirection"><s:selectItems value="#{rolesListing.roles}" var="role" label="#{role.roleName}"/><s:convertEntity/></h:selectManyCheckbox>
In the above example “userAccount.userRoles” is the form value (users associated roles) and the rolesListing.roles is bunch of roleids and rolename from entity named SiteRole.The helper class RolesListing is as follows
@Name("rolesListing")@Scope(ScopeType.APPLICATION)
public class RolesListing {
@In(create=true) EntityManager entityManager;
@Outprivate List<siterole> roles;
@Factory("roles")
public List<siterole> getRoles(){
roles= entityManager.createNamedQuery("SiteRole.findRoles").getResultList();
return roles;
}
public void setRoles(List<siterole> roles){
this.roles = roles;
}
}
Important things to make sure, this seam tag work are
a) Make sure the #{userAccount.userRoles} and #{rolesListing.roles} are of same type for example i made both of them as List. If they are different type, you will encounter “Conversion Error setting value”.
b) Make sure the
c) In my next post i will explain the @ManyToMany relationship between userAccount entity and Roles entity using a USER_ROLE join table.