2010-03-12 27 views
9

Bir hashmap üzerinden geçmeye çalışıyorum ve hashmap anahtarını id ile bir onay kutusu göstermeye çalışıyorum ve hashmap değerini etiketleyin. Bunun için goblen sözdiziminin ne olduğunu bilen var mı?hashmap aracılığıyla goblen döngüsü

Alkış Dimitris

Böyle anahtar kümesi aracılığıyla döngü gerekir

cevap

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> 

Sınıf dosyası:

@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); 
} 

Bu derlenmiş değil, ama Başlamana yardım etmelisin.

+1

Çok teşekkürler !!! Tam olarak aradığım şey bu. Bir yöntem eklemek zorunda kaldı. kamu String getLabelValue() { \t dönüş this.getMyMap() ile (this.currentKey.); } ve değerini değiştirin ve HashMap'in değerlerini görüntülemek ve anahtarları bir sonraki sayfaya geçirmek için . Çok teşekkürler ... – Sfairas