总结之Struts

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

在用Struts的

<logic:iterate id="testqclist" name="testQCActionForm" ="result" indexId="index" >

<bean:write name="testqclist" property="saamsampleid" /> <bean:write name="testqclist" property="sampleid" />

<input type="hidden" name="calcresultVal" value="<bean:write name="testqclist" property="calcresult" />" >

</logic:iterate>

说明:

参数是Property参数

参数名称

说明

name

struts-config里面的ActionForm 的名字

property

Form里面的一个arraylist属性

id

标识名,和里面标签的name名字一样

IndexId

显示记录条数的index,

indexId:的有个用法是:<logic:iterate i>里面有checkbox的时候,要选择特定的记录数量的时候,可以用到这个属性。

这时要在FORM里添加几个属性

1. 给每个属性添加一个集合属性

2. 添加一个方法保存FORM的对象。返回一个 ArrayList 对象给FORM原有的那个

Result 属性。

在JSP页面里面

每个显示的数据里面都加一个HIDEEN

当提交的时候就可以吧记录保存在FORM里面的集合属性里面。

代码如下

Action:

protected void performDBTask (ActionFormBase actionForm,

HttpServletRequest request,

HttpServletResponse response

) throws SQLException{

String methodName = "performDBTask()";

//ActinForm

TestQCActionForm testQCActionForm = (TestQCActionForm)actionForm;

try{

ArrayList handExcel = testQCActionForm.handExcelList();

testQCActionForm.setResultlist(handExcel);

actionForm.setForward ("success");

} catch (Exception e){

System.err.println (className + "." + methodName + "==>" + e.getMessage ());

}

}

FORM代码=======================================

private String[] checkboxVal;

private String[] testidVal;

private String[] sampleidVal;

private String[] qctypecdVal;

private String[] datesampledVal;

private String[] testseqVal;

private String[] calcresultVal;

private String[] saamsampleidVal;

//Hander Select data

public ArrayList handExcelList (){

java.util.ArrayList list = new java.util.ArrayList ();

if (checkboxVal != null && checkboxVal.length > 0){

for (int i = 0; i < checkboxVal.length; i++){

int chkVal = Integer.parseInt(checkboxVal[i]);

TestQCActionForm checkform = new TestQCActionForm ();

checkform.setSaamsampleid (datesampledVal[chkVal].toString());

checkform.setSaamsampleid(saamsampleidVal[chkVal].toString());

checkform.setSampleid (sampleidVal[chkVal].toString());

checkform.setQctypecd (qctypecdVal[chkVal].toString());

checkform.setTestid (testidVal[chkVal].toString());

checkform.setTestseq (testseqVal[chkVal].toString());

checkform.setCalcresult(Double.parseDouble(calcresultVal[chkVal]));

checkform.setDatesampled(datesampledVal[chkVal].toString());

list.add (checkform);

}

}

return list;

}

JSP页面===========================================

<lims:notEmpty name="testQCActionForm" property="result">

<logic:iterate id="testqclist" name="testQCActionForm" property="result" indexId="index" >

<tr bgcolor="#FFFFFF" onMouseOver="this.bgColor='#ECF4F9'" onMouseOut="this.bgColor='#FFFFFF'">

<td height="26" bgcolor="#EEEEEE"><div align= "center" >

<input type="checkbox" name="checkboxVal" value="<%=index%>" >

</div></td>

<td ><div align="center">

<input type="hidden" name="saamsampleidVal" value="<bean:write name="testqclist" property="saamsampleid" />" >

<bean:write name="testqclist" property="saamsampleid" />

</div></td>

<td bgcolor="#EEEEEE"><div align="center" >

<input type="hidden" name="sampleidVal" value="<bean:write name="testqclist" property="sampleid" />" >

<bean:write name="testqclist" property="sampleid" />

</div></td>

<td><div align="center">

<input type="hidden" name="qctypecdVal" value="<bean:write name="testqclist" property="qctypecd" />" >

<bean:write name="testqclist" property="qctypecd" />

</div></td>

<td ><div align="center">

<input type="hidden" name="testidVal" value="<bean:write name="testqclist" property="testid" />" >

<bean:write name="testqclist" property="testid" />

</div></td>

<td bgcolor="#EEEEEE"><div align="center">

<input type="hidden" name="testseqVal" value="<bean:write name="testqclist" property="testseq" />" >

<bean:write name="testqclist" property="testseq" />

</div></td>

<td ><div align="center">

<input type="hidden" name="calcresultVal" value="<bean:write name="testqclist" property="calcresult" />" >

<bean:write name="testqclist" property="calcresult" />

</div></td>

<td ><div align="center">

<input type="hidden" name="datesampledVal" value="<bean:write name="testqclist" property="datesampled" />

" > <bean:write name="testqclist" property="datesampled" />

</div></td>

</tr>

</logic:iterate>

</lims:notEmpty>

就是在啊ACTION里面转向(actionForm.setForward ("success");)之前设置显示信息

首先要在.propertits里面设置

如:

del.msg= You Deleted Form(s) successfully

在ACTION里面

ActionErrors errors = new ActionErrors ();

errors.add ("addInfoMsg", new ActionError ("del.msg"));

saveErrors (request, errors);

actionForm.setForward ("success");

web-xml

application

com.lims.resources.Resource

此外还有一些做法

表示 显示集合中的所有错误

表示显示存储在missing.name关键字的错误

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航