Tapestry循环通过hashmap

Sfa*_*ras 9 java tapestry

我正在尝试遍历一个hashmap并显示一个数字复选框,其id为hashmap的键,并标记hashmap的值.任何人都知道挂毯的语法是怎样的?

干杯迪米特里斯

Hen*_*ing 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>
Run Code Online (Sandbox Code Playgroud)

班级档案:

@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);
}
Run Code Online (Sandbox Code Playgroud)

我没有编译这个,但它应该可以帮助你开始.