The problem you're hitting is that there's really no concept of a "key" in a
List - it's just an ordered collection of objects.  The closest you'd find
is the contains( Object o) method, but that looks for the entire object and
not just a key.  I would suggest using a HashMap for what you're looking
for.

As for the "break" on logic:iterate, I think the closest way to approximate
this is by setting up a flag for the loop such that you can do this:

<set up loop flag>
<logic:iterate....>
  <logic:equals name="loopFlag" value="true">
        (do important stuff)
  </logic:equals>
  < set loopFlag to false when criteria are met>
</logic:iterate>

This won't save the loop iterations, but will keep extra content from being
written after you meet the criteria.  If possible, however, you may want to
trim your data set in the Action before you ever get to the jsp.

-Rob

-----Original Message-----
From: Derek Shen [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 05, 2003 12:51 PM
To: [EMAIL PROTECTED]
Subject: how to acccess a specific object inside a List efficiently


I have trouble to access a specific object inside a List based on a key. 
Before the first page, I load all the objects(meetings) into a list and only

show the name of the meeting to the user. By following the link (with id as 
parameter), user goes to the next page. Based on the id, I want to show the 
detail of the object (meeting). For my current implementation, I have to 
iterate through every single object in the list and try to match the key. It

works, but pretty stupid. Is there a better way to do it? Or should I use 
Hashmap (keyed by id) at the very beginning instead?

Also, to use logic:iterate, is there something like a "break"?

Thanks!
ds

First page:
      <logic:iterate id="m" name="meetings">
          <li>
            <html:link
              forward="showMeeting"
              paramId="id"
              paramProperty="id"
              paramName="m">
              <bean:write name="m" property="name"/>&nbsp;
            </html:link>
         </li>
      </logic:iterate>
It will build:
http://myproject/showMeeting?id=1

Second Page:
<logic:iterate id="row" name="meetings">
<logic:equal name="row" property="id" value="<%=request.getParameter   
("id")%>">
  <tr>
    <TH align="right" width="50%">Meeting Name:</TH>
    <TD align="left"><bean:write name="row" property="name"/></TD>
  </tr>
  ...
</logic:equal>
</logic:iterate>

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.  
http://join.msn.com/?page=features/virus


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to