2011-12-02 26 views
0

我想寫一個包含Struts 2的文本框標記,如下一個JSP:動態名struts2的文本框

我想用一個變量的值的名稱動態地分配給該文本框我聲明先前在代碼如下:

<s:if test="patient.procedureCode.size > 0"> 

<% int i=0;%> 

<s:iterator value="patient.procedureCode" id ="procedureCode">  

    <%i++; %> 

    <% if((i%2) > 0) { %>  

     <tr class="dbText" > 

      <td > 
       <s:checkbox value="false" fieldValue="%{#procedureCode.objectid}" name="objectid" theme="simple" /> 
      </td>   

      <td class="BasicText" >        
       <s:textfield value="%{proceddateVar}" size="10" theme="simple" readonly="false" name=""/> 
      </td> 
     </tr>  
    <%} %> 

</s:iterator> 

我想給文本字段名稱是等於變量i的當前值。 請指教。

+0

你的意思是你賦值爲'%{procedateVar}'的值相同嗎? –

+0

看我更新的帖子 –

回答

0

我不知道你所說的可變

電流值的意思,但如果你不喜歡

<s:textfield label="What is your name?" name="%{var_val}" /> 

這名稱的文本字段的變量 所以,我相信,當電流值迭代器將迭代它將把對象放在值棧的頂端,你可以參考這個使用OGNL表達式

id has been Deprecated. Use `var` instead 

有在IteratorStatus對象的不同屬性到位scriplet這麼使用它們

index int    zero-based index value. 
count int    index + 1 
first boolean  returns true if it is the first element 
last boolean  returns true if it is the last element 
even boolean  returns true if the count is an even number. 
odd  boolean  returns true if the count is an odd number. 
modulus  int  takes an int value and returns the modulus of count 

我個人絕不會喜歡混合scriplet當事情在乾淨的方式實現

這裏有Iterator對象的細節 Iterator Status

+0

「變量的當前值」我的意思是: A.整數變量i初始化爲0. B.在每次迭代期間,我遞增1. C.我想分配i(在每次迭代期間)的當前值添加到在該迭代中生成的文本域。 D.在第一次迭代期間,我想將文本字段命名爲'0',在第二次迭代'1'期間等等。 –