2013-07-12 22 views
3

我需要做一個選擇,包括選項1,2,3一個簡單的INT選擇模型... 250創建掛毯

<p> 
<t:label for="quantity2" style="width:40%" /> 
<t:select t:id="quantity2" t:model="literal:0,1,2,3,4,5,6,7" /> 
</p> 

此代碼的工作,但我想有數字0到250!

謝謝你,對不起我的英語不好。

回答

2

select component's documentation「當模型參數是一個字符串時,它將在逗號分開,當模型參數是一個字符串列表時,每個元素都被視爲一個選擇選項。

所以,我建議你使用字符串列表:

TML

<t:select t:id="quantity2" value="selectedQuantity2" t:model="quantities" /> 

的Java

public List<String> getQuantities() { 
    // create a list of strings from "1" to "250" 
} 
+1

它的作品:)謝謝:)我已經嘗試了一個列表,但整數列表。 – user2007861

+1

http://stackoverflow.com/help/someone-answers –

0

更改您的選擇做這樣的:

<t:select t:id="quantity2" value="selectedQuantity2" t:model="Quantity2Model" /> 

在你的網頁類,這樣做

@Property 
private SelectModel quantity2Model; 

@Inject 
SelectModelFactory smf; 

void setupRender() 
{ 
    List<int> values = new ArrayList<int>(); 
    for (int i = 0; i <= 250; ++i) 
    { 
     values.Add(i); 
    } 
    quantity2Model = smf.create(values, "name"); 
} 

警告:我從來沒有聽說過掛毯,直到我看了你的問題,我不擅長Java,所以這只是基於我的研究here。祝你好運!

+1

謝謝你,但它無法正常工作。它返回一個空的異常(帶有smf.create)。我不明白爲什麼它如此複雜!這只是一個int列表... – user2007861

+0

我同意,它似乎比我想象的更難。 – dss539