如何将 ac:forEach 标记的循环索引附加到 struts 选择/文本标记的属性?
例如。
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>
<c:forEach begin="2" end="${pageView.guestCount}" varStatus="gC">
<div class="section guest-details">
<html:select property='title_guest<c:out value="${gC.index}"/>'>
<html:options collection="titles" property="code" labelProperty="value" />
</html:select>
</div>
</c:forEach>
引发以下错误
javax.servlet.jsp.JspException at org.apache.struts.taglib.html.SelectTag.calculateMatchValues(SelectTag.java:246)
现在,当我调试代码时,<html:select ...
它显示当它设置的属性属性时,它的设置"title_guest<c:out value="${gC.index}"/>"
可能是上述异常的原因。
另外,我应该提到,如果我使用上述格式将循环索引附加到标准 html 标记属性(如<select>
标记),则代码可以正常工作。
例如
<c:forEach begin="2" end="${pageView.guestCount}" varStatus="gC">
<div class="section guest-details">
<select name='title_guest<c:out value="${gC.index }"/>'>
<option value="">Select Title</option>
</select>
</div>
</c:forEach>
正确输出预期的 HTML
我做错了什么,我应该使用 EL 创建将填充 html:select 标记的“属性”属性的字符串吗?
更新
还尝试了以下代码段,但也没有用
<html:select property="title_guest${gC.index}">
而且,这也不起作用
<c:set var="guestTitle">title_guest${gC.index}</c:set>
<html:select property="${guestTitle}" styleClass="{required: true}">
<html:options collection="titles" property="code" labelProperty="value" />
</html:select>