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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
| package exemple05;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class Client extends ActionSupport {
private String identifiant;
private String motdepasse;
private int profession;
private int[] repas;
private List<Profession> listeProfessions=new ArrayList<Profession>();
private List<Repas> listeRepas=new ArrayList<Repas>();
private Map<Integer,String> niveauProfession=new HashMap<Integer,String>();
public Client()
{
}
//retourne les options qui pré-coché
public int [] getDefaultRepas(){
//listKey="id" c'est la valeur de l'id, voir comment est-ce que un Repas est instencié
System.out.println("Dans la méthode getDefaultRepas");
return new int [] {1, 2}; // De cette façon ci les deux options son coché par défaut
}
// retourner une liste de professions
public List<Profession> getListeProfessions() {
listeProfessions.add(new Profession(1, "Informaticien"));
listeProfessions.add(new Profession(2, "Formateur"));
listeProfessions.add(new Profession(3, "SGBDM"));
listeProfessions.add(new Profession(4, "Responsable reseau"));
return listeProfessions;
}
// getter et setter
public Map<Integer, String> getNiveauProfession() {
niveauProfession.put(1, "BAC");
niveauProfession.put(2, "BAC1");
niveauProfession.put(3, "BAC2");
return niveauProfession;
}
public void setListeProfessions(List<Profession> listeProfessions) {
this.listeProfessions = listeProfessions;
}
public int getProfession() {
return profession;
}
public void setProfession(int profession) {
this.profession = profession;
}
public List<Repas> getListeRepas() {
listeRepas.add(new Repas(1, "Repas du midi"));
listeRepas.add(new Repas(2, "Repas du soir"));
return listeRepas;
}
public void setListeRepas(List<Repas> listeRepas) {
this.listeRepas = listeRepas;
}
public int[] getRepas() {
return repas;
}
public void setRepas(int repas[]) {
this.repas = repas;
}
public String getIdentifiant() {
return identifiant;
}
public void setIdentifiant(String identifiant) {
this.identifiant = identifiant;
}
public String getMotdepasse() {
return motdepasse;
}
public void setMotdepasse(String motdepasse) {
this.motdepasse = motdepasse;
}
public String execute() {
System.out.println("Dans la méthode execute");
return SUCCESS;
}
// ajouter les informations du client dans la session
public String ajouter()
{
// vérifier les saisies, en cas d'erreur retourner sur la page de saisie
if(this.identifiant.equals("") || this.motdepasse.equals(""))
{
return "input";
}
// pas d'erreur
else
{
return "afficher";
}
}
}
// Classe de gestion des professions
class Profession
{
private int idProfession;
private String nom;
public Profession(int idProfession, String nom)
{
this.idProfession=idProfession;
this.nom=nom;
}
public int getIdProfession() {
return idProfession;
}
public void setIdProfession(int idProfession) {
this.idProfession=idProfession;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom=nom;
}
}
//Classe de gestion des repas
class Repas
{
private int id;
private String nom;
public Repas(int id, String nom)
{
this.id=id;
this.nom=nom;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
} |
Partager