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
| /**
* Société sélectionnée
*/
private Societe selectedSociete;
/**
* Holder de la recherche en session
*/
private RechercheListeHolder rechercheListeHolder;
@Override
public void init() {
selectedSociete = new Societe();
selectedSociete.setId(Long.valueOf(rechercheListeHolder.getSelectedId()));
}
@Override
public void prerender() {
if (!this.isPostBack()) {
// mode édition
if (selectedSociete.getId() != null) {
try {
selectedSociete = societesService.findSocieteByPk(selectedSociete.getId());
} catch (Exception e) {
MessageSupport.addMessage(FacesMessage.SEVERITY_ERROR, OgtfConstants.RESOURCE_OGTF_MESSAGE, "ogtf.erreur.baseDonnees");
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}
}
}
public String modifier() {
return OgtfConstants.OUTCOM_SUCCESS;
}
/**
* Retour à la page de liste
* @return
*/
public String retour() {
rechercheListeHolder.clearMessages();
return OgtfConstants.OUTCOM_SUCCESS;
}
public SocietesService getSocietesService() {
return societesService;
}
public void setSocietesService(SocietesService societesService) {
this.societesService = societesService;
}
public Societe getSelectedSociete() {
return selectedSociete;
}
public void setSelectedSociete(Societe selectedSociete) {
this.selectedSociete = selectedSociete;
}
public RechercheListeHolder getRechercheListeHolder() {
return rechercheListeHolder;
}
public void setRechercheListeHolder(RechercheListeHolder rechercheListeHolder) {
this.rechercheListeHolder = rechercheListeHolder;
}
public ParameterService getParameterService() {
return parameterService;
}
public void setParameterService(ParameterService parameterService) {
this.parameterService = parameterService;
}
public FileService getFileService() {
return fileService;
}
public void setFileService(FileService fileService) {
this.fileService = fileService;
}
public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
PhaseId phaseId = event.getPhaseId();
if (phaseId.equals(PhaseId.ANY_PHASE)) {
event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
event.queue();
} else if (phaseId.equals(PhaseId.UPDATE_MODEL_VALUES)) {
UploadedFile file = (UploadedFile) event.getNewValue();
if (file != null) {
if (file.getContentType().startsWith("image")) {
try {
// chargement de l'image
Image image = ImageIO.read(file.getInputStream());
// vérification des dimensions
if (image.getWidth(null) > OgtfConstants.IMAGE_WIDTH || image.getHeight(null) > OgtfConstants.IMAGE_HEIGHT) {
throw new ImageDimensionException("Dimensions non respectées [" + OgtfConstants.IMAGE_WIDTH + " x "
+ OgtfConstants.IMAGE_HEIGHT + "]");
}
// if (selectedSociete.getPrenomRepresentant() != null && selectedSociete.getPrenomRepresentant().trim().length() > 0
// && selectedSociete.getNomRepresentant() != null && selectedSociete.getNomRepresentant().trim().length() > 0) {
//
// // racine d'OGTF
// String ogtfPath = parameterService.getParameterValue(UploadConstants.UPLOAD_DOMAIN_KEY, UploadConstants.OGTF_PATH_KEY);
//
// // répertoire des données Sociétés
// String societesDir = parameterService.getParameterValue(UploadConstants.UPLOAD_DOMAIN_KEY,
// UploadConstants.OGTF_DONNEES_SOCIETES_DIR_KEY);
//
// // nom du fichier uploadé sur le serveur
// String signatureFileName = FileService.PREFIX_SIGNATURE + selectedSociete.getPrenomRepresentant() + "-"
// + selectedSociete.getNomRepresentant() + "." + file.getName();
//
// // upload de l'image
// if (ogtfPath != null && ogtfPath.trim().length() > 0 && societesDir != null && societesDir.trim().length() > 0) {
// String signatureFilePath = ogtfPath + File.pathSeparator + societesDir + File.pathSeparator + signatureFileName;
// fileService.saveFile(signatureFilePath, file.getBytes());
// }
// }
// MessageSupport.addMessage(FacesMessage.SEVERITY_ERROR, OgtfConstants.RESOURCE_OGTF_MESSAGE, "ogtf.edition.erreur.image.io");
} catch (ImageDimensionException ile) {
MessageSupport.addMessage(FacesMessage.SEVERITY_ERROR, OgtfConstants.RESOURCE_OGTF_MESSAGE,
"ogtf.edition.erreur.image.dimensions", new String[] { String.valueOf(OgtfConstants.IMAGE_WIDTH),
String.valueOf(OgtfConstants.IMAGE_HEIGHT) });
logger.error(ile.getMessage(), ile);
} catch (IOException ioe) {
MessageSupport.addMessage(FacesMessage.SEVERITY_ERROR, OgtfConstants.RESOURCE_OGTF_MESSAGE, "ogtf.edition.erreur.image.io");
logger.error(ioe.getMessage(), ioe);
}
}
}
}
} |
Partager