2010-03-12 5 views
9

Sto provando a scorrere un'hashmap e visualizzare un numero di caselle con id la chiave dell'hashmap e etichettare il valore dell'hashmap. Qualcuno sa come sia la sintassi degli arazzi per quello?Loop di arazzo tramite hashmap

Acclamazioni Dimitris

risposta

14

Si dovrebbe essere in grado di scorrere il set di chiavi in ​​questo modo:

<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> 

file di classe:

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

non ho compilato questo, ma è dovrebbe aiutarti a iniziare.

+1

Grazie mille !!! Questo è esattamente quello che stavo cercando. Ho dovuto aggiungere un metodo. public String getLabelValue() { \t return this.getMyMap(). Get (this.currentKey); } e modificare per visualizzare i valori della mia HashMap e passare le chiavi alla pagina successiva. Grazie mille ... – Sfairas