Differences between revisions 1 and 2
Revision 1 as of 2006-07-22 03:09:25
Size: 1784
Editor: ip70-181-145-212
Revision 2 as of 2009-09-20 23:12:39
Size: 1786
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 39: Line 39:
 * [http://www.learntechnology.net/struts-nested.do Struts Nested] -- Rick Reumann  * [[http://www.learntechnology.net/struts-nested.do|Struts Nested]] -- Rick Reumann

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/>


<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}" />

Additional information:

JSTLTagsNested (last edited 2009-09-20 23:12:39 by localhost)