1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<html>
<head>
<title>Test struts-logic Iterate Tag</title>
</head>
<body bgcolor="white">
<%
{
java.util.ArrayList list = new java.util.ArrayList();
list.add("First");
list.add("Second");
list.add("Third");
list.add("Fourth");
list.add("Fifth");
pageContext.setAttribute("list", list, PageContext.PAGE_SCOPE);
int intArray[] = new int[]
{ 0, 10, 20, 30, 40 };
pageContext.setAttribute("intArray", intArray, PageContext.PAGE_SCOPE);
}
%>
<div align="center">
<h1>Test struts-logic Iterate Tag</h1>
</div>
<jsp:useBean id="bean" scope="page" class="org.apache.struts.webapp.exercise.TestBean" />
<jsp:useBean id="list" scope="page" class="java.util.ArrayList" />
<h3>Test 1 - Iterate Over A String Array [0..4]</h3>
<ol>
<logic:iterate id="element" name="bean" property="stringArray" indexId="index">
<li>
<em>
<bean:write name="element" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
</ol>
<h3>Test 2 - Iterate Over A String Array [0..2]</h3>
<ol>
<logic:iterate id="element" name="bean" property="stringArray" indexId="index" length="3">
<li>
<em>
<bean:write name="element" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
</ol>
<h3>Test 3 - Iterate Over A String Array [3..4]</h3>
<ol>
<logic:iterate id="element" name="bean" property="stringArray" indexId="index" offset="3">
<li>
<em>
<bean:write name="element" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
</ol>
<h3>Test 4 - Iterate Over A String Array [1..3]</h3>
<ol>
<logic:iterate id="element" name="bean" property="stringArray" indexId="index" offset="1" length="3">
<li>
<em>
<bean:write name="element" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
</ol>
<h3>Test 5 - Iterate Over an Array List</h3>
<ol>
<logic:iterate id="item" name="list" indexId="index">
<li>
<em>
<bean:write name="item" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
</ol>
<h3>Test 6 - Iterate Over an Array List [0..2]</h3>
<ol>
<logic:iterate id="item" name="list" indexId="index" offset="0" length="3">
<li>
<em>
<bean:write name="item" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
</ol>
<h3>Test 7 - Iterate Over an Array List [2..4]</h3>
<ol>
<logic:iterate id="item" name="list" indexId="index" offset="2" length="3">
<li>
<em>
<bean:write name="item" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
</ol>
<h3>Test 8 - Iterate Over an int array</h3>
<ol>
<logic:iterate id="item" name="intArray" indexId="index">
<li>
<em>
<bean:write name="item" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
</ol>
<h3>Test 9 - Iterate Over an int array [0..2]</h3>
<ol>
<logic:iterate id="item" name="intArray" indexId="index" length="3">
<li>
<em>
<bean:write name="item" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
</ol>
<h3>Test 10 - Iterate Over an int array [2..4]</h3>
<ol>
<logic:iterate id="item" name="intArray" indexId="index" offset="2" length="3">
<li>
<em>
<bean:write name="item" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
</ol>
</body>
</html>
|