Hello I have an User with some Roles User.class
public class User {
private Long id;
private String firstName;
private String lastName;
private Set<Role> roles = new HashSet<Role>(0);
public Long getId() { return id; } public void setId(Long id) { this.id = id; }
public String getFirstName() { return this.firstName; }
public void setFirstName(String firstname) { this.firstName = firstname; }
public String getLastName() { return this.lastName; }
public void setLastName(String lastname) { this.lastName = lastname; }
public Set<Role> getRoles() { return this.roles; }
public void setRoles(Set<Role> roles) { this.roles = roles; }
}
Role.class
public class Role {
private Long id;
private String name;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
在jsp档案中,我想要作出多种选择,与选定的数值(用户拥有的模块)具有所有的作用。
我曾尝试过:
<select id="roles" name="roles" multiple="true" size="4">
<c:forEach items="${allRoles}" var="role">
<option value="${role.id}" <c:if test="${role.id == roleSelected.id}">selected</c:if> >${role.name}</option>
</c:forEach>
</select>
where allRoles represent all the role, roleSelected represent the user.roles. but it not working, is there any manner to say something in jstl like " if role in user.roles then selected " ? thank for any advise.
<>Update:
some its
public static boolean contains(Collection<?> collection, Object object) {
System.out.println("coll = " + collection.toString());
System.out.println("obj="+ object.toString());
System.out.println("res="+ collection.contains(object));
return collection.contains(object);
}
在原木中,在第二次测试中应做到:
coll = [Id :2;Code: TESTName: Temp Manager;Enabled: true;Comment: ;]
obj=Id :1;Code: ADMName: ADMIN;Enabled: true;Comment: For Adminstrators;
res=false
coll = [Id :2;Code: TESTName: Temp Manager;Enabled: true;Comment: ;]
obj=Id :2;Code: TESTName: Temp Manager;Enabled: true;Comment: ;
res=false
coll = [Id :2;Code: TESTName: Temp Manager;Enabled: true;Comment: ;]
obj=Id :3;Code: RHHName: TECHNOMEDIA;Enabled: true;Comment: Dfdf;
res=false
coll = [Id :2;Code: TESTName: Temp Manager;Enabled: true;Comment: ;]
obj=Id :4;Code: RESPONSName: Refd;Enabled: true;Comment: Sdsds;
res=false