InfoCenter Home > 4.2.2.3.7.1.2a: JSP syntax: The repeat tag results set and the associated beanThe <tsx:repeat> iterates over a results set. The results set is contained within a JavaBean. The bean can be a static bean (for example, a bean created by using the IBM WebSphere Studio database wizard) or a dynamically generated bean (for example, a bean generated by the <tsx:dbquery> syntax). The following table is a graphic representation of the contents of a bean, myBean:
Some observations about the bean:
The following table compares using the <tsx:repeat> to iterate over static bean versus a dynamically generated bean:
Implicit and explicit indexingExamples 1, 2, and 3 show how to use the <tsx:repeat>. The examples produce the same output if all indexed properties have 300 or fewer elements. If there are more than 300 elements, Examples 1 and 2 will display all elements, while Example 3 will show only the first 300 elements. Example 1 shows implicit indexing with the default start and default end index. The bean with the smallest number of indexed properties restricts the number of times the loop will repeat. <table> <tsx:repeat> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="city" /></tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="address" /></tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="telephone" /></tr></td> </tsx:repeat> </table> Example 2 shows indexing, starting index, and ending index: <table> <tsx:repeat index=myIndex start=0 end=2147483647> <tr><td><tsx:getProperty name="serviceLocationsQuery" property=city(myIndex) /></tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property=address(myIndex) /></tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property=telephone(myIndex) /></tr></td> </tsx:repeat> </table> Example 3 shows explicit indexing and ending index with implicit starting index. Although the index attribute is specified, the indexed property city can still be implicitly indexed because the (myIndex) is not required. <table> <tsx:repeat index=myIndex end=299> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="city" /t></tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="address(myIndex)" /></tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="telephone(myIndex)" /></tr></td> </tsx:repeat> </table> Nesting <tsx:repeat> blocksYou can nest <tsx:repeat> blocks. Each block is separately indexed. This capability is useful for interleaving properties on two beans, or properties that have sub-properties. In the example, two <tsx:repeat> blocks are nested to display the list of songs on each compact disc in the user's shopping cart. <tsx:repeat index=cdindex> <h1><tsx:getProperty name="shoppingCart" property=cds.title /></h1> <table> <tsx:repeat> <tr><td><tsx:getProperty name="shoppingCart" property=cds(cdindex).playlist /> </td></tr> </table> </tsx:repeat> </tsx:repeat>
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|