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="txtboxDIS" 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 &lt;s:textfield tag

Am I missing something ?

Vinoth Kumar C M
  • 10,378
  • 28
  • 89
  • 130

3 Answers3

2
<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.
lschin
  • 6,745
  • 2
  • 38
  • 52
1

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>
Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
  • It does not work either . I don't get an error. But I don't get what I require . I get something like Desc_&lts:property value="#itemIndex.count"/&gt as id. – Vinoth Kumar C M Apr 19 '11 at 07:14
1

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" />
Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118