2012-11-12 126 views
0

我有上的問題預先選擇的值的與支柱2如何預選擇上選擇一個選項(在Struts 2)

我使用的標記值=「國家」定位到String country =「Japan」,select從列表(字符串列表)中加載元素。

但是,在加載時,select只是針對列表中的第一項。

看:

<s:select list="countries" value="country" label="Conutry" 
            headerKey="null" name="country" id="selectCountry" 
            /> 


public List<String> countries; 
public String country; 
..... 

public Countries(){ 
     countries=dao.list(); 
} 


......... 

getter and setter 

........ 
//Action Used to get information 
public getInfo(){ 
    country="USA" 
} 
+0

在代碼'contry' vs'country'中有錯字嗎? –

+0

哈哈對不起,我寫的問題的錯誤!..但是在muy代碼是正確的..謝謝! – rafuru

回答

1

嘗試:

<s:select list="countries" 
      value="country" 
      label="Conutry" 
      headerKey="country" 
      headerValue="contry" 
      name="countries" 
      id="selectCountry"/> 

headerKey表明您發佈的值。
headerValue將顯示在列表中。

+0

謝謝! ,但headerkey/value是hardTyped選項,如「選擇一個選項」,並帶有「null」鍵。因此,如果我輸入headerKey =「country」和headerValue =「country」,我將獲得一個「國家」作爲預選選項,並且我希望在該動作中設置選項。 – rafuru

+0

@rafuru你有'公共字符串getInfo(){}',你可以使用'headerValue =「%{info}」'從行動 – Jaiwo99

+0

返回一個字符串hmm%{info}正常工作!謝謝!! – rafuru

相關問題