2011-08-05 38 views
2

我的任務是改進頁面上的表單驗證。Java struts從索引中獲取屬性

該網站使用的.jsp /綠豆/支柱等。目前有在頁面頂部的循環打印錯誤到屏幕上:

<nested:iterate id="currentError" property="wizard.errors" type="java.lang.String" indexId="counter"> 
    <tr> 
     <td valign="top" class="wizardErrorText" width="2%"> 
      &gt; 
     </td> 
     <td class="wizardErrorText"> 
      <span errorId=""> 
       <bean:write name="currentError"/> 
      </span> 
     </td> 
    </tr> 
</nested:iterate> 

現在,當驗證失敗我已經改變了現有方法略微表示驗證失敗的字段的ID以及錯誤消息。然後,我設置了一個類似的循環,將驗證失敗的字段的id打印到JavaScript讀取的區域,並相應地突出顯示字段。

而不是有另一個循環我想使用indexId查找數組中的值並將其包含在errorId中。

有沒有人建議如何做到這一點?

我試過jsp.getProperty和其他一些方法,但沒有運氣。

感謝 加里

+0

在*數組或*數組中?它看起來不像currentError是一個HashMap,所以在一個單獨的並行數組中的ID? –

+0

是的想法是在一個平行的數組,我希望使用從第一個數組迭代計數器挑出其他表中的相應條目不幸的wizard.erroredInputs [計數器]似乎沒有工作或任何其他方法我試過。 – Gary

回答

1

您應該能夠像這樣:

<bean:write name="wizard" property="erroredInputs[counter]" /> 

或者,完整的例子:

<nested:iterate id="currentError" property="wizard.errors" type="java.lang.String" indexId="counter"> 
    <tr> 
     <td valign="top" class="wizardErrorText" width="2%"> 
      &gt; 
     </td> 
     <td class="wizardErrorText"> 
      <span errorId="<bean:write name="wizard" property="erroredInputs[counter]" />"> 
       <bean:write name="currentError"/> 
      </span> 
     </td> 
    </tr> 
</nested:iterate> 

更多信息可以在這裏找到:https://struts.apache.org/1.x/struts-taglib/indexedprops.html