<%@ page session="false" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.Hashtable" %>
<%@ taglib uri="/ixtaglib" prefix="jsptut" %>

<html>
	<head>
		<title>Loop TagLibrary example</title>
	</head>
	
	<body>
		This example shows how to use a simple loop-tag with dynamic attributes.<br>
	
	 <UL><br>

		<% int x = 0; %>
   <LI><I>Loop:</I><br>
		<table border="2">
			<jsptut:loop count="<%=10%>">
				<tr>
					<jsptut:loop count="<%=Math.random() * 10f%>">
						<td><%=x++%></td>
					</jsptut:loop>
				</tr>
			</jsptut:loop>
		</table>	
   <LI><I>For 1-10:</I><br>
		
   <jsptut:for index="i" from="<%=1%>" to="<%=10%>">
   <% out.print(i) ; %>
   </jsptut:for> 
   <LI><I>For 20-30:</I><br>
		
   <jsptut:for index="i1" from="<%=20%>" to="30">
   <%= i1 %>
   </jsptut:for> 
   <LI><I>For 0-15:</I><br>
   <% int x1 = 15 ; boolean isFirst = true ;%>
   <jsptut:for index="i1" from="0" to="<%=x1%>">
   <%= i1 %>
   <% if(x1 == 12 && isFirst) {
     		x1 = 5 ;
     		isFirst = false ;
   		 }
   %>
   </jsptut:for> 
   <LI><I>ForEach with Vector:</I><br>
   <% Vector theVector = new Vector() ;
      theVector.addElement("Hello" );
      theVector.addElement("World" );
   %>
   <jsptut:foreach item="element"  list="<%= theVector.elements() %>" >
   <%= element %>
   </jsptut:foreach> 

   <LI><I>ForEach with Hashtable:</I><br>
   <% Hashtable theHash = new Hashtable() ;
      theHash.put("k1","Hello" );
      theHash.put("k2","World" );
   %>
   <jsptut:foreach item="key"  list="<%= theHash.keys() %>" >

   Key: <%= key %> Value: <%= theHash.get(key) %><br>
   </jsptut:foreach> 

		<LI><I>Currency:</I><br>
   Format currency 9.3 = <jsptut:currency value="<%=9.3%>"/><br>
   Format currency 9.313 = <jsptut:currency value="9.313"/>
   <LI><I>ForEach with currency output:</I><br>
   <% Vector theVectorC = new Vector() ;
      theVectorC.addElement(new Double("21.34") );
      theVectorC.addElement(new Double("34.456") );
   %>
   <jsptut:foreach item="element"  list="<%= theVectorC.elements() %>" >
   <% boolean expr = ((Double)element).doubleValue()> 25.0 ;%>
   <jsptut:if expr="<%=expr%>" >
   <%=element%> format=<jsptut:currency value="<%=(Double)element%>"/><br>
   </jsptut:if>
   </jsptut:foreach> 
		<LI><I>If true:</I><br>
   <jsptut:if expr="true">
     Hello here is the body
   </jsptut:if>
		<LI><I>If false:</I><br>
   <jsptut:if expr="false">
     When you this, the if Taglib implementation is wrong!
   </jsptut:if>
   <BR>After if-Tag --- Body write this out
   </UL>
   <br>
		End...
	</body>
</html>