I found difficulties in iterating a multilevel collection on jsp.
@Entity
@Table(name = "Establishment")
public class Establishment extends Basis<Long> {
@Column(name = "code")
private Long code; // will be used for link to the entity if the name will be updated
@Column(nullable = false)
private String name;
private String establishmentType;
@ManyToOne(optional = true)
private Establishment establishment;
@Column(name = "establishment_id", insertable = false, updatable = false)
private Long establishmentId;
@OneToMany(mappedBy = "establishment", orphanRemoval = true, cascade = CascadeType.ALL)
private List<Establishment> establishments = new ArrayList<>();
//getters & setters
}
jsp code
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page session="true" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="myTags" %>
<myTags:hierarchy list="${establishmentList}"/>
tag file:
<%@ attribute name="list" required="true" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="myTags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:if test="${!empty list}">
<ul>
<c:forEach var="entity" items="${list}">
<li><c:out value="${entity.name}"/></li>
<%--${fn:length(e.establishments)}--%>
<myTags:hierarchy list="${entity.establishments}"/>
</c:forEach>
</ul>
</c:if>
if i use 'list' in <c:forEach var="entity" items="${list}">
like here I cannot use ${entity.name}
, if use <c:forEach var="entity" items="${establishmentList}">
i get recursive call of first-only element. So, how should I edit tag file to make this work?