在用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参数
|
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; //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> |