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
| public class ActionAffichage extends ActionSupport implements ApplicationAware {
private FacadeJoueur facade;
private String position;
private Collection<String> positions;
private String nom;
private String prenom;
private String biographie;
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Collection<String> getPositions() {
return facade.getAllPositions();
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public String getBiographie() {
return biographie;
}
public void setBiographie(String biographie) {
this.biographie = biographie;
}
@Override
public String execute() throws Exception{
try {
for (String s : getPositions()) {
position = s;
this.setPosition(position);
switch (position) {
case "AILIER":
id=facade.ajouterJoueur(nom, prenom, biographie, Joueur.Position.valueOf("AILIER"));
break;
case "MENEUR":
facade.ajouterJoueur(nom, prenom, biographie, Joueur.Position.valueOf("MENEUR"));
break;
case "PIVOT":
facade.ajouterJoueur(nom, prenom, biographie, Joueur.Position.valueOf("PIVOT"));
break;
case "ARRIERE":
facade.ajouterJoueur(nom, prenom, biographie, Joueur.Position.valueOf("ARRIERE"));
break;
case "AILIER FORT":
facade.ajouterJoueur(nom, prenom, biographie, Joueur.Position.valueOf("AILIER FORT"));
break;
}
}
return SUCCESS;
} catch (JoueurDejaExistant joueurDejaExistant) {
this.addFieldError("nom", getText("erreur.joueur"));
} catch (PositionNotFoundException e) {
this.addFieldError("position",getText("erreur.position"));
}
return INPUT;
}
@Override
public void validate() {
if (Objects.isNull(nom) || nom.length()<4){
this.addFieldError("nom",getText("erreur.nom"));
}
if (Objects.isNull(prenom) || prenom.length()<4){
this.addFieldError("prenom",getText("erreur.prenom"));
}
if (Objects.isNull(biographie) || biographie.length()<4){
this.addFieldError("biographie",getText("erreur.biographie"));
}
if (Objects.isNull(position)){
this.addFieldError("position",getText("erreur.champposition"));
}
}
@Override
public void setApplication(Map<String, Object> map) {
this.facade=(FacadeJoueur) map.get("facade");
if(Objects.isNull(this.facade)){
this.facade=new FacadeJoueurImpl();
map.put("facade",this.facade);
}
}
} |
Partager