You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Derek Shen <ds...@hotmail.com> on 2003/02/05 18:50:58 UTC

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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org