學習筆記,每一天我們都在進步。
2007/01/07 21:51
LIST页面
<logic:iterate id="item" name="list" scope="request"  indexId="indexid" offset="0">
 <tr>
   <td height="30" align=center>${pageScope.indexid+1}</td>
   <td align=center><a href='${ad.url}' target=_blank>${item.url}</a> </td>
   <td align=center>${item.budget}</td>
   <td align=center>${item.pvmin}</td>
   <td align=center>${item.consumeall}元/${ad.pvall}次</td>
   <td align=center>${item.consumeday}元/${ad.pvday}次</td>
   <td align=center>
   <html:link page="/manage.do" paramId="id" paramName="item" paramProperty="adid">编辑</html:link>
   <html:link page="/delete.do" paramId="id" paramName="item" paramProperty="adid" onclick="return confirmDelete()">删除</html:link>
   </td>
 </tr>
</logic:iterate>


根据条件判断出哪个list
<logic:equal parameter="page" value="1">
<b>2006-12-1 至 2006-12-1 分日统计报告</b>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=0 width="100%" borderColorLight=#cccccc
border=1>
 <TR>
   <TD width="20%" height="25" align="center" bgcolor="#cccccc"><B>日期</B></TD>
   <TD width="15%" align="center" bgcolor="#cccccc"><B>次数</B></TD>
   <TD width="25%" align="center" bgcolor="#cccccc"><B>金额</B></TD>
   <TD width="40%" align="center" bgcolor="#cccccc"><B>所属类别</B></TD>
 </TR>
 <TR>
   <TD width="8%" height="25" align="center"> </TD>
   <TD align="center"> </TD>
   <TD align="center"> </TD>
   <TD align="center"> </TD>
 </TR>
 <TR>
   <TD width="8%" height="25" align="center" bgcolor="#f0f0f0"> </TD>
   <TD align="center" bgcolor="#f0f0f0"> </TD>
   <TD align="center" bgcolor="#f0f0f0"> </TD>
   <TD align="center" bgcolor="#f0f0f0"> </TD>
 </TR>
 <TR>
   <TD height="25" bgcolor="#f0f0f0"><B>总计</B></TD>
   <TD height="25" bgcolor="#f0f0f0"><B>0次</B></TD>
   <TD colSpan=1 rowSpan=2 bgcolor="#f0f0f0"><B>0元</B></TD>
   <TD colSpan=1 rowSpan=2 bgcolor="#f0f0f0"> </TD>
 </TR>
</TABLE>
</logic:equal>

LIST页面嵌套2层循环
grouplist是一个java.util.List<Group>  
clientlist是Group中的一个变量,类型也是一个List,以下内容是显示grouplist中的内容并将group中的每个client也显示。
<logic:iterate id="group" name="grouplist" scope="request"  indexId="indexid" offset="0">
<!-- 第一层循环grouplist -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr bgcolor="#f0f0f0" height=24>
   <td width="70%" height="25" align="left" bgcolor="#cccccc">&nbsp;&nbsp;&nbsp;${group.groupname}&nbsp;&nbsp;&nbsp;</td>
   <td width="30%" align="right" bgcolor="#cccccc">
     <a href="#">改名</a>
     <html:link page="/deletegroup.do" paramId="id" paramName="group" paramProperty="groupid" onclick="return confirmDelete()">删除</html:link>&nbsp;&nbsp;
   </td>
 </tr>
</table>
<table width=100% border=0 cellpadding="3" cellspacing="1">
 <logic:iterate id="client" name="group"  property="clientlist" type="java.util.Vector" offset="0">  <tr>
<!-- 第二层循环clientlist -->
   <td width=100%>&nbsp;&nbsp;
     <html:multibox property="selecteduserids">
      ${client.value}
     </html:multibox>
     <a href='client_info.jsp?aid=${client.value}' target=_blank>${client.label}</a>
   </td>
 </tr>
 </logic:iterate>
 </table>
<br>
</logic:iterate>




一个form里有多个submit时 ,action里如何判断来自哪个submit提交的
<html:submit property="dosubmit" value=" 生成订单 "/>

if (request.getParameter("dosubmit") != null) {
 。。。
}


表单中部分内容是根据用户状态动态生成的时,将生成的方法写在reset方法里
   public void reset(ActionMapping mapping, HttpServletRequest request) {
       provinceSelect = ProvinceSelect.getProvinceSelect();
       this.manageid = -1;
       this.province = "";
       // this.groupid = -1;
       this.selectedProduct = null;
       Account a = (Account) request.getSession().getAttribute("user");
       if (a != null) {
           ManageSelect ms = new ManageSelect(a.getIAccountId());
           this.setManageSelect(ms.getManageSelect());
           GroupSelect gs = new GroupSelect(a.getIAccountId());
           this.setGroupSelect(gs.getGroupSelect());
           ProductSelect ps = new ProductSelect();
           this.setProductSelect(ps.getProductSelect(a.getCProduct()));
       }
   }


要使用validation.xml验证,form类要继承org.apache.struts.validator.ValidatorForm
同时form类里没有validate验证方法。
个人认为validation只做一些书写规则的校验,例如非空、数字之类的,
action里调用一些业务逻辑的校验,最好将校验规则也脱离action单独出来。

select、checkbox和raido的动态显示
以下property中的元素都是LabelValueBean的形式
select的最简单
<html:select property="groupid">
<html:optionsCollection property="groupSelect"/>
</html:select>


radio的
<logic:iterate id="manage" name="accountForm" property="manageSelect" indexId="indexid" offset="0">
   <html:radio property="manageid" value="${manage.value}"/>${manage.label}
</logic:iterate>

checkbox的
在formbean中selectedProduct是一个value形式的数组,内容是页面被选中的这些元素的value。
<logic:iterate id="product" name="accountForm" property="productSelect" indexId="indexid" offset="0">
     <html:multibox property="selectedProduct">
     ${product.value}
     </html:multibox>
     ${product.label}
</logic:iterate>

如果需要确省选中某项只要在reset方法里给对应的form里的变量赋上要选中项的value值就行了。
游客
2007/01/08 00:10
不错,都是些常用到的。
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]