2011-04-19 90 views
2

我有一個迭代使用支柱迭代器和我試圖動態名稱的IDS錯誤而2

<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> 

在上面的代碼中,表中的行,與類=「normRow」已產生適當的id ,但在文本字段的情況下,我收到以下錯誤

org.apache.jasper.JasperException: /WEB-INF/jsp/screens/role.jsp(150,102) Unterminated &lt;s:textfield tag 

我是否錯過了什麼?

回答

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> 
  • 始終使用表達式$ {}的代替< S:屬性 />(除了類型轉換),請參見Struts2的Performance Tuning
  • 對於Struts2標記的屬性,始終使用OGNL
+0

+1 - 這是正確的做法 – 2011-04-20 06:27:02

1

只是嘗試像

<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> 
+0

它也行不通。我沒有收到錯誤。但我沒有得到我所需要的。我得到了類似Desc_&lts:property value =「#itemIndex.count」/&gt的id。 – vinoth 2011-04-19 07:14:49

1

定製JSP標籤沒有被內的其他JSP標記的屬性進行評估。一個scriptlet然而應當在這種情況下工作:

<s:textfield name="roleDescription" cssClass="txtboxDIS" 
    id='Desc_<%= ((org.apache.struts2.views.jsp.IteratorStatus)pageContext.findAttribute("itemIndex")).getCount() %>' 
    size="30" disabled="true" />