iterate的嵌套使用

04-04-22 thy3368
<%@ page contentType="text/html;charset=UTF-8" %>

<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<bean:define id="mainCategories" name="mainCategories" scope="request" type="java.util.ArrayList"/>

<bean:define id="subCategories" name="subCategories" scope="request" type="java.util.ArrayList"/>

<html>

<head>

<title>subCategory view</title>

</head>

<body alink="#006699" marginheight="2" marginwidth="2" topmargin="2" leftmargin="2" bgcolor="#ffffff">

<table width="200" border="1" align="center">

<tr>

<td align="center" valign="middle">

<logic:iterate id="item" name="subCategories" type="com.hjc.jbar.product.SubCategory">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr valign="top">

<td rowspan="4"><img src="<%=item.getPicURL()%>" border="0" width="120" height="120" /></td>

<td height="18"><b><a href="ProductViewAction.do?action=productDetail&productID=<%=item.getSubCategoryID()%>"><%=item.getSubject()%></a></b></td>

</tr>

<tr>

<td></td>

<td bgcolor="#cccccc"></td>

</tr>

<tr>

<td></td>

<td bgcolor="#cccccc"></td>

</tr>

<logic:iterate id="product" name="item" property="products" type="com.hjc.jbar.product.Product">

<tr>

<td>

<font size="-2" face="arial">

<%=product.getSubject()%>

</font>

</td>

<td></td>

</tr>

</logic:iterate>

<tr> </tr>

</table>

</logic:iterate>

</td>

</tr>

</table>

</body>

</html>

注意,在Hibernate配置XML中,把LAZY设置为FLASE,清单如下:

<class name="com.hjc.jbar.product.SubCategory" table="subCategory" dynamic-update="true">

<id name="subCategoryID" column="subCategoryID">

<generator class="identity"/>

</id>

<property name="subject" length="80" not-null="true"/>

<property name="body" length="2147483647" not-null="true"/>

<property name="picURL" length="255" not-null="true"/>

<set name="products" cascade="delete" inverse="true" lazy="false">

<key column="subCategoryID"/>

<one-to-many class="com.hjc.jbar.product.Product"/>

</set>

<many-to-one name="mainCategory" column="mainCategoryID" cascade="all" not-null="true"/>

</class>

thy3368
2004-04-22 16:52

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<bean:define id="mainCategories" name="mainCategories" scope="request" type="java.util.ArrayList"/>
<bean:define id="subCategories" name="subCategories" scope="request" type="java.util.ArrayList"/>
<html>
<head>
<title>subCategory view</title>
</head>
<body alink="#006699" marginheight="2" marginwidth="2" topmargin="2" leftmargin="2" bgcolor="#ffffff">

<table width="200" border="1" align="center">
  <tr>
    <td align="center" valign="middle">
	<logic:iterate id="item" name="subCategories" type="com.hjc.jbar.product.SubCategory">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  
	  <tr valign="top">
	    <td rowspan="4"><img src="<%=item.getPicURL()%>"  border="0" width="120" height="120" /></td>
	    <td height="18"><b><a href="ProductViewAction.do?action=productDetail&productID=<%=item.getSubCategoryID()%>"><%=item.getSubject()%></a></b></td>
	  </tr>
	  <tr>
	    <td></td>
	    <td bgcolor="#cccccc"></td>
	  </tr>
	  <tr>
	    <td></td>
	    <td bgcolor="#cccccc"></td>
	  </tr>
		<logic:iterate id="product" name="item" property="products" type="com.hjc.jbar.product.Product">
		  <tr>
		    <td>
		    <font size="-2" face="arial">
			<%=product.getSubject()%>
		    </font>
			</td>
		    <td></td>
		  </tr>
		</logic:iterate>
    <tr> </tr>
	</table>
	</logic:iterate>
	</td>
  </tr>
</table>
</body>
</html>

注意,在Hibernate配置XML中,把LAZY设置为FLASE,清单如下:

	<class name="com.hjc.jbar.product.SubCategory" table="subCategory" dynamic-update="true">
		<id name="subCategoryID" column="subCategoryID">
			<generator class="identity"/>
		</id>
		<property name="subject" length="80" not-null="true"/>
		<property name="body" length="2147483647" not-null="true"/>
		<property name="picURL" length="255" not-null="true"/>
		<set name="products" cascade="delete" inverse="true" lazy="false">
			<key column="subCategoryID"/>
			<one-to-many class="com.hjc.jbar.product.Product"/>
		</set>
		<many-to-one name="mainCategory" column="mainCategoryID" cascade="all" not-null="true"/>	
	</class>

猜你喜欢