2010-03-12 114 views
9

我想通過哈希映射循環,並顯示一個數字複選框與ID哈希映射的關鍵和標籤的哈希值的值。任何人都知道這個tapestry語法是怎麼樣的?Tapestry循環通過哈希映射

乾杯 季米特里斯

回答

14

你應該能夠循環通過按鍵這樣的:

<form t:type="Form"> 
    <t:Loop t:source="myMap.keySet()" t:value="currentKey"> 
     <input type="Checkbox" t:type="Checkbox" t:id="checkbox" 
      t:value="currentValue"/> 
     <label t:type="Label" for="checkbox">${mapValue}</label> 
    </t:Loop> 
</form> 

類文件:

@Property 
private Object currentKey; 

@Persist 
private Set<String> selection = new HashSet<String>(); 

public Map<String,String> getMyMap() { 
    ... 
} 

public boolean getCurrentValue() { 
    return this.selection.contains(this.currentKey); 
} 

public void setCurrentValue(final boolean currentValue) { 
    final String mapValue = this.getMapValue(); 

    if (currentValue) { 
     this.selection.add(mapValue); 
    } else { 
     this.selection.remove(mapValue); 
    } 
} 


public String getMapValue() { 
    return this.getMyMap().get(this.currentKey); 
} 

我沒有編這一點,但它應該幫助你開始。

+1

非常感謝!這正是我正在尋找的。必須添加一個方法。 public String getLabelValue(){ \t return this.getMyMap()。get(this.currentKey); } and change 爲了顯示我的HashMap的值並將按鍵傳遞到下一頁。 非常感謝... – Sfairas 2010-03-15 16:29:59