如何使用el访问存储在列表中的对象的属性,其中列表存储在jsp中的对象中

时间:2015-04-02 17:21:49

标签: java jsp

我的GroupObject

public class GroupObject {
    private String group_name;
    private List<GroupDetails> groupMembersList;


public String getGroup_name() {
    return group_name;
}
public void setGroup_name(String group_name) {
    this.group_name = group_name;
}
public String getGroup_id() {
    return group_id;
}
public void setGroup_id(String group_id) {
    this.group_id = group_id;
}
public String getGroup_description() {
    return group_description;
}
public void setGroup_description(String group_description) {
    this.group_description = group_description;
}
public List<GroupDetails> getGroupMembersList() {
    return groupMembersList;
}
public void setGroupMembersList(List<GroupDetails> groupMembersList) {
    this.groupMembersList = groupMembersList;
}

GroupDetails对象存储在上面的列表中

public class GroupDetails {

private String member_name;
private String member_usertype;


public String getMember_name() {
    return member_name;
}

public void setMember_name(String member_fullname) {
   this.member_name = member_fullname;

}
public String getMember_usertype() {
    return member_usertype;
}
public void setMember_usertype(String member_usertype) {
    this.member_usertype = member_usertype;
}

}

我有一个servlet,用于填充&#39;列表&#39;来自具有GroupDetials对象实例的GroupObject。

我正在访问&#39; member_name&#39;和&#39; member_usertype&#39; GroupDetails实例的属性

使用以下代码段

在jsp中访问
<c:forEach var="member" items="${members_list}">
                                        <li class="list-group-item title">
                                        <img src="${pageContext.request.contextPath}/css/images/user.png" class="img img-circle" style="display: inline" />
                                        <strong style="display:inline;">  ${member.groupMembersList.member_name} <h5 style="display: inline;">(${member.groupMembersList.member_usertype})</h5></strong>
                                        </li> 
                                    </c:forEach>

我想遍历groupMemberList元素并访问它们的corressponding member_name和member_usertype,但上面的jsp不起作用。我无法访问&#39; member_name&#39;和&#39; member_usertype&#39;。 请帮忙。

1 个答案:

答案 0 :(得分:0)

你再次需要一个forEach循环:

<strong style="display:inline;">
    <c:forEach items="${member.groupMembersList}" var="groupDetails">
        ${groupDetails.member_name} ... ${groupDetails.member_usertype}
    </c:forEach>
</strong>