Hi ,

The struts example app has example of the "enumerate" tag in the
registration.jsp - it's the pre-JDK1.2 version of "iterate", so that's a
template you could use.

"iterate" is almost identical, the only difference being that the collection
which is walked through need only implement the Collection interface, which (I
guess) was only introduced as part of the base package in JDK1.2.

Vivek

Here's a jsp snippet I have which uses the "iterate" tag, and points directly to
a Collection (implemented by an ArrayList). The elements of the ArrayList
(ProjectDecorators) are simple objects whose sole purpose is to contain strings
so this table can display them. They are populated in the Action snippet, and
the collection is then registered with the session, and then the jsp is invoked.

The snippet of the Action which sets up the collection labelled "projects" (and
then forward to this JSP) follows after the jsp...

SNIPPET OF JSP: apologies for indenting. My email program is messing it about a
bit.

<table border="1" width="100%">
     <tr>
     <th align="center" width="35%">
          Id
     </th>

     <th align="center" width="35%">
          Name
     </th>
     <th align="center" width="35%">
          Description
     </th>
     <th align="center" width="20%">
          Client Name
     </th>
     <th align="center" width="10%">

     </th>
     </tr>

<!-- since I'm not specifying the "property" parameter, the "name" specifies
     the attribute name of the Collection itself. -->
<struts:iterate id="project" name="projects">
     <tr>
          <td>
               <struts:htmlProperty name="project" property="id"/>
          </td>
               <td>
               <struts:link href="EditProject.do?action=Update" name="project"
property="parameterMap">
                    <struts:htmlProperty name="project" property="name"/>
               </struts:link>
          </td>
               <td>
               <struts:htmlProperty name="project" property="description"/>
          </td>
               <td>
               <struts:htmlProperty name="project" property="clientName"/>
          </td>
               <td>
               <struts:link href="EditProject.do?action=Delete" name="project"
property="parameterMap">
                    Del
               </struts:link>
          </td>
     </tr>
</struts:iterate>
</table>

SNIPPET OF ACTION:

     theProjects = theProjectService.getProjectList();
     projectList = new ArrayList();
     theIterator = theProjects.values().iterator();

     while(theIterator.hasNext()){
          theProjectAttributes = (HashMap)theIterator.next();
          theProjectDecorator = new ProjectDecorator();
          theProjectDecorator.setId(
               ((Integer)theProjectAttributes.get(Project.ID)).toString()
          );

theProjectDecorator.setName((String)theProjectAttributes.get(Project.NAME));

theProjectDecorator.setClientName((String)theProjectAttributes.get(Project.CLIENT_NAME));


theProjectDecorator.setDescription((String)theProjectAttributes.get(Project.DESCRIPTION));

          projectList.add(theProjectDecorator);
     }//end while

     session.setAttribute("projects", projectList);





Mike Campbell <[EMAIL PROTECTED]> on 12/18/2000 05:02:11 PM

Please respond to [EMAIL PROTECTED]

To:   "struts (E-mail)" <[EMAIL PROTECTED]>
cc:    (bcc: Vivek Iyer/Chicago SPL/Group)
bcc:  Vivek Iyer/Chicago SPL/Group

Subject:  iterate tags, I don't get it.



Can someone point me either to somewhere in the example app where iterates
are used, and if not, give me a short rundown on how the iterate tag relates
to beans created in the Action classes?

Thanks

-------------------------------------------------
Mike Campbell        email: [EMAIL PROTECTED]
S1 Corporation       voice: 678-421-4641
Software Engineer      fax: 678-421-4865
R&D Department         web: www.s1.com
-------------------------------------------------

Title: iterate tags, I don't get it.

Can someone point me either to somewhere in the example app where iterates are used, and if not, give me a short rundown on how the iterate tag relates to beans created in the Action classes?

Thanks

-------------------------------------------------
Mike Campbell        email: [EMAIL PROTECTED]
S1 Corporation       voice: 678-421-4641
Software Engineer      fax: 678-421-4865
R&D Department         web: www.s1.com
-------------------------------------------------

Reply via email to