File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts 2:  Iterating through Alphabetized Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2:  Iterating through Alphabetized Map" Watch "Struts 2:  Iterating through Alphabetized Map" New topic
Author

Struts 2: Iterating through Alphabetized Map

Pierre Coulbert
Greenhorn

Joined: Sep 09, 2008
Posts: 8
Hi all,

I have a requirement to display a collection grouped alphabetically. I've created an arrayList alphaList, which contains each letter of the alphabet, and I can iterated through that ok. In each iteration, though, I want to access my Map of objects by that letter, the value of which contains an arrayList of objects beginning with that letter. Sort of like this:

<s:iterator value="alphaList">//iterates from A-Z
<li><s roperty /><br>//displays letter of alphabet
<s:iterator value="alphabetizedMap.get(<s roperty /> ">//key='A' value = aList, an array of Program objects
<li><s:a href="%{url}"><s roperty value="title" escape="false"/></s:a><br>//program.getUrl, program.getTitle
</li>
</s:iterator>
<br>
</s:iterator>

Where alphaList is a List of letters A-Z, alphabetizedMap is a bean containing letters as keys and a List of Objects (Programs, as it happens) with getTitle() beginning with that letter.

The call to <s:iterator value="alphabetizedMap.get(<s roperty /> "> does not work. I want to get with whichever letter of the alphabet I am iterating through i.e. alphabetizedMap.get('A'), alphabetizedMap.get('B') and use it to access my list of Program objects associated to that letter by key\value.

I hope I explained this clearly. Any help on this greatly appreciated.
Pierre Coulbert
Greenhorn

Joined: Sep 09, 2008
Posts: 8
found the answer to my question:

<s:iterator value="alphaList" id="letter">
<li><s roperty /><br>
<s:iterator value="getAlphabetizedMapValue(#letter)">
<li><s:a href="%{url}"><s roperty value="title" escape="false"/></s:a><br>
</li>
</s:iterator>
<br>
</s:iterator>

Reference the value of the outermost iteration with "#" symbol and giving it an id ("letter"). Found by reading documentation of iterator tag.
 
wood burning stoves
 
subject: Struts 2: Iterating through Alphabetized Map
 
Similar Threads
how to make an iterator iterate only once ?
s:if String comparison not working
if tag, collections, and startsWith
help needed with iterator tag in struts2
iterate over nested ArrayList in struts2