1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
package beans;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.AjaxBehaviorEvent;
/**
* Bean managé pour stocker la valeur du h:selectOneMenu. Ce bean permettra de génerérer un liste dynamique de composants h:inputText ainsi que leur "id" respectif.
*
* @author francois.robin
*/
@ManagedBean
@ViewScoped
public class ValeurBean
{
/**
* valeur qui representera la saisie du h:selectOneMenu.
*/
private int value = 0;
/**
* Map qui stocke les valeurs saisies. première string : identifiant du composant ; seconde string : valeur saisie dans le composant;
*/
private Map<String, String> composantValues = new HashMap<String, String>();
/**
* initialise la Map d'identifiants de du composant. Cette méthode est invoquée par AJAX lors de la modification de la valeur dans la combo box.
*
* @param e evenement AJAX
*/
public void onChangeListener(AjaxBehaviorEvent e)
{
composantValues.clear();
for (int i = 0; i < value; i++)
{
String composantId = String.format("compId_%d", i);
String composantDefaultValue = String.format("valeur initiale de %s", composantId);
composantValues.put(composantId, composantDefaultValue);
}
}
/**
* @return the value
*/
public int getValue()
{
return value;
}
/**
* @param value the value to set
*/
public void setValue(int value)
{
this.value = value;
}
/**
* @return the composantValues
*/
public Map<String, String> getComposantValues()
{
return composantValues;
}
/**
* @param composantValues the composantValues to set
*/
public void setComposantValues(Map<String, String> composantValues)
{
this.composantValues = composantValues;
}
/**
* renvoie la liste des identifiants h:inputText
*
* @return liste des identifiants
*
*/
public List<String> getComposantsIds()
{
return new ArrayList(composantValues.keySet());
}
/**
* reproduit dans la console les valeurs saisies dans les h:inputText
*/
public void verifSaisies()
{
System.out.println("Vérification des saisies .. : " + value);
for (String valeur : composantValues.values())
{
System.out.println(valeur);
}
}
} |