Error while using Iterator in struts 2
I am having an iterator and I am trying to dynamically name the ids
<s:iterator value="roleScreenDetailsList" status ="itemIndex">
<table>
<tr class="normRow" id="row_<s:property value="#itemIndex.count"/>" style="display:none;">
<td colspan="8" class="bdr0">
<s:textfield name="roleDescription" cssClass="txtboxDI开发者_开发百科S" id="Desc_<s:property value="#itemIndex.count"/>" size="30" disabled="true" />
</td>
</table>
</s:iterator>
In the above code , the table row , with class ="normRow" has proper ids generated , but in case of the text field , I am getting the following error
org.apache.jasper.JasperException: /WEB-INF/jsp/screens/role.jsp(150,102) Unterminated <s:textfield tag
Am I missing something ?
<s:iterator value="roleScreenDetailsList" status ="itemIndex">
<table>
<tr id="row_${itemIndex.count}">
<td><s:textfield name="roleDescription" id="Desc_%{#itemIndex.count}" /></td>
</tr>
</table>
</s:iterator>
- Always use expression ${} instead of <s:property /> (except for Type Conversion), see the Performance Tuning of Struts2.
- Always use OGNL for attributes of Struts2 tag.
Just try something like
<s:iterator value="roleScreenDetailsList" status ="itemIndex">
<table>
<tr class="normRow" id="row_<s:property value="#itemIndex.count"/>" style="display:none;">
<td colspan="8" class="bdr0">
<s:textfield name="roleDescription" cssClass="txtboxDIS" id='Desc_<s:property value="#itemIndex.count"/>' size="30" disabled="true" />
</td>
</table>
</s:iterator>
Custom jsp tags are not evaluated inside attributes of other jsp tags. A scriptlet however should work in this case:
<s:textfield name="roleDescription" cssClass="txtboxDIS"
id='Desc_<%= ((org.apache.struts2.views.jsp.IteratorStatus)pageContext.findAttribute("itemIndex")).getCount() %>'
size="30" disabled="true" />
精彩评论