在jsp页面中创建java动态行
好的。。。这是一个很长的问题。但我认为答案很简单。虽然我自己找不到解决办法。在jsp页面中,不能将四列放在一行中。我想在页面中使用循环再添加10行,其中字段的名称如下
row1_amount, row1_loantype,row1_date, row1_status
row2_amount, row2_loantype,row2_date, row2_status
等等
更清楚
property="cib_borrower_report.loanType"
将在表单中的所有十行中
property="cib_borrower_report.loanType1"
property="cib_borrower_report.loanType2"
property="cib_borrower_report.loanType3"
现在,如果我想使用循环命名,怎么做?如何添加1,2,3。。在房地产行业
如果我可以动态地这样做,它将帮助我获取值的类型。所以请帮忙
<table border="0" cellpadding="1"><tbody>
<tr>
<td ><label class="desc"><bean:message key="label.cib.new.report.taken.amount"/></label></td>
<td><html:text property="cib_borrower_report.takenAmount" styleClass="SingleLineTextField" size="20"></html:text></td>
<td> </td>
<td><label class="desc"><bean:message key="label.cib.new.report.loan.type"/></label></td>
<td><html:text property="cib_borrower_report.loanType" styleClass="SingleLineTextField" size="20"></html:text></td>
<td> </td>
<td><label for="cib_borrower_report.reportingDate" class="desc"><bean:message key="label.cib.new.reporting.date" /></label></td>
<td>
<table><tbody><tr>
<td><input type="Text" name="cib_borrower_report.reportingDate" id="cib_borrower_report.reportingDate" style="cib_borrower_report.reportingDate" class="SingleLineTextField" maxlength="10" size="10" tabindex="1" ></td>
<td><a href="javascript:NewCal('cib_borrower_report.reportingDate','mmddyyyy')"><img align="middle" src="Images/cal.jpg" width="20" height="20" border="0" alt="Pick a date"></a></td>
</tr></tbody></table>
</td>
<td> </td>
<td><label class="desc"><bean:message key="label.cib.new.loan.status"/></label></td>
<td align="center">
<html:select property="cib_borrower_report.loanStatus" styleId="searchQuery1">
<html:option value="STD">STD</html:option>
<html:option value="SMA">SMA</html:option>
<html:option value="SS">SS</html:option>
<html:option value="DF">DF</html:option>
<html:option value="BL">BL</html:option>
</html:select>
</td>
</tr>
</tbody></table>
# 1 楼答案
在struts logic taglib上,您可以使用Svtruts 1中记录的iterate标记。x站点:
您的代码将具有以下结构:
对于您需要的交互类型,您可以通过其索引访问您的属性,如下所示:
这将生成一个具有name属性的文本字段,如mycollection[0]。prop如果提交了包含此逻辑的表单,则将更新集合mycollection的元素0的属性prop
还要注意,Struts团队鼓励您只使用Struts标记,而不能使用Struts 1中所述的JSTL标记。x站点:
# 2 楼答案
在JSP
<foreach/>
标记中,可以使用varStatus
属性获取索引,并将其添加到属性名中我建议使用列表而不是命名属性名(看起来更好,并扩展了动态方法)。对于列表,您仍然需要循环输出,但是会有一个更干净的JSP(一开始就很难看)
# 3 楼答案
要在JSP页面中执行循环,可以使用JSTL
<c:forEach>
。 您需要下载JSTL的一个实现,请参阅下面的链接资源: