I am self-learning JQuery and UI.
I have two entities:
- AppUser
@Entity
@Table(name = "app_user")
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(...)
private List<AppRole> roles;
- AppRole
@Entity
@Table(name = "app_role")
private Integer id;
private String name;
On JSP I can get the role names using this:
<c:forEach items="${user.roles}" var="list">${list.name}</c:forEach>
What I am trying to achieve is - To display the user details with the roles in a bootstrap modal.
I tried the following as suggested here (any many other).
for (var i = 0; i < userroles.length; i++) {
$('#roleslist').append(
'<option value="' + userroles[i] + '">'
+ userroles[i]
+ '</option>');
}
This give me close to what I am trying to achieve but it gives me the weird looking object list in the dropdown like below:
[com.spring.boot.rocks.model.AppRole[ id=1 ], com.spring.boot.rocks.model.AppRole[ id=2 ], com.spring.boot.rocks.model.AppRole[ id=3 ]]
Question: How do I get the names of roles using JQuery for above scenario? Is there a way I can display/populate the drop-down with role-id and role-name?
I know there is a big disconnect somewhere but any clue on this will be helpful.