Struts <nested:xxx> tags are used for two purposes:

  • to iterate through and display content of nested beans
  • to generate proper names of input elements, so these name could be parsed on input phase

JSTL <c:forEach> helps to iterate and display content of nested beans only, because JSTL is positioned as render-only technology. Therefore choosing JSTL <c:forEach> tag over Struts <nested:xxx> tags is not an obvious choice.

Code samples by Rick Reumann.

List of Department POJOs. Each Department has a List of Employees. Department properties: List employees, String deptName Employee properties: String empName, String email

Struts <nested:xxx> tags

<nested:iterate property="departments">
    <nested:text property="deptName"/><br/>
        <nested:iterate property="employees">
            Employee: <nested:text property="empName"/>
            E-mail: <nested:text property="email"/><br/>
        </nested:iterate>
</nested:iterate>

JSTL

<c:forEach items="${companyForm.departments}" var="dept" varStatus="deptStatus">
    Department: <html:text property="departments[${deptStatus.index}].deptName" 
                           value="${dept.deptName}" />
        <c:forEach items="${dept.employees}" var="emp" varStatus="empStatus">
            Employee: <html:text property="departments[${deptStatus.index}].
                       employees[${empStatus.index}].empName" value="${emp.empName}" />
            E-mail: <html:text property="departments[${deptStatus.index}].
                       employees[${empStatus.index}].email" value="${emp.email}" />
        </c:forEach>
</c:forEach>

Additional information:

  • No labels