2010-03-12 169 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