簡體   English   中英

如何在我的操作中從JSP獲取更新的列表值?

[英]How to get updated list values from JSP in my action?

我有一個JSP,在其中迭代列表並創建可編輯表。

<s:iterator value="test" id="countryList">
  <tr>
    <td><s:textfield name="countryCode" value="%{countryCode}" theme="simple" /></td>
    <td><s:textfield name="countryName" value="%{countryName}" theme="simple" /></td>
  </tr>
 </s:iterator>

我的列表:

List<Country> test = new ArrayList<Country>();  

國家/地區類別:

public class Country {
    private String countryCode;
    private String countryName;


and the getter setters......

並說我像這樣填充列表:

Country country = new Country();
Country country1 = new Country();

country.setCountryCode("1");
country.setCountryName("India");

country1.setCountryCode("2");
country1.setCountryName("US");

test.add(country);
test.add(country1);

現在,當我在JSP中更改countrycodecountryname的值時,應該在操作中獲取更新的值。 但是我不能。 有沒有辦法獲取這些更新的值。

params攔截器使用索引屬性訪問填充列表時,需要創建Country對象。

<s:iterator value="test" id="countryList" status="stat">
  <tr>
    <td><s:textfield name="countryList[%{#stat.index}].countryCode" value="%{countryCode}" theme="simple" /></td>
    <td><s:textfield name="countryList[%{#stat.index}].countryName" value="%{countryName}" theme="simple" /></td>
  </tr>
 </s:iterator>

要讓Struts填充列表,您應該在xml配置中使用類型轉換批注或等效項。

@Element(value = Country.class)
@Key(value = String.class)
@KeyProperty(value = "countryCode") 
@CreateIfNull(value = true)
private List<Country> countryList = new ArrayList<Country>;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM