You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by Apache Wiki <wi...@apache.org> on 2006/07/22 05:09:26 UTC

[Struts Wiki] Update of "JSTLTagsNested" by MichaelJouravlev

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Struts Wiki" for change notification.

The following page has been changed by MichaelJouravlev:
http://wiki.apache.org/struts/JSTLTagsNested

New page:
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:
 * [http://www.learntechnology.net/struts-nested.do Struts Nested] -- Rick Reumann