diff --git a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java index d0a0de66b69c5ace2cd43f552ca4b616b376f1bb..dd59f5a9a73eda0d3b419b51a82bac85b02359e0 100644 --- a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java +++ b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java @@ -38,7 +38,7 @@ public class PetDetailsManagedBean implements Serializable{ private Pet pet; private Long selectedVaccineId; - private String vaccinationDate; // yyyy-MM-dd + private Date vaccinationDate; // yyyy-MM-dd private List allVaccines; @PostConstruct @@ -69,33 +69,33 @@ public class PetDetailsManagedBean implements Serializable{ this.selectedVaccineId = selectedVaccineId; } - public String getVaccinationDate() { + public Date getVaccinationDate() { return vaccinationDate; } - public void setVaccinationDate(String vaccinationDate) { + public void setVaccinationDate(Date vaccinationDate) { this.vaccinationDate = vaccinationDate; } // Método para vacunar public String vaccinate() { - if (selectedVaccineId == null || vaccinationDate == null || vaccinationDate.isEmpty()) { + if (selectedVaccineId == null || vaccinationDate == null /*|| vaccinationDate.isEmpty()*/) { FacesContext.getCurrentInstance().addMessage(null, new javax.faces.application.FacesMessage("Debe seleccionar vacuna y fecha")); return null; } try { - Date date = new SimpleDateFormat("yyyy-MM-dd").parse(vaccinationDate); - Vaccination v = vaccinationService.create(pet.getId(), selectedVaccineId, date); + //Date date = new SimpleDateFormat("yyyy-MM-dd").parse(vaccinationDate); + Vaccination v = vaccinationService.create(pet.getId(), selectedVaccineId, vaccinationDate); // refrescar la mascota para mostrar la nueva vacunación this.pet = petService.get(pet.getId()); FacesContext.getCurrentInstance().addMessage(null, new javax.faces.application.FacesMessage("Vacunación creada correctamente")); - } catch (ParseException e) { + } /*catch (ParseException e) { FacesContext.getCurrentInstance().addMessage(null, new javax.faces.application.FacesMessage("Formato de fecha inválido")); - } catch (IllegalArgumentException e) { + }*/ catch (IllegalArgumentException e) { FacesContext.getCurrentInstance().addMessage(null, new javax.faces.application.FacesMessage(e.getMessage())); } diff --git a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VaccineManagedBean.java b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VaccineManagedBean.java index c2b7df9bfc99a3e2b53dca20f4b795aa139705e2..a9acee8f0bd830bc1222dd80bc48ca6854882951 100644 --- a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VaccineManagedBean.java +++ b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VaccineManagedBean.java @@ -1,16 +1,20 @@ package es.uvigo.esei.xcs.jsf; +import java.io.Serializable; import java.util.List; import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; +import javax.faces.view.ViewScoped; import javax.inject.Named; import es.uvigo.esei.xcs.domain.entities.Vaccine; import es.uvigo.esei.xcs.service.VaccineService; @Named("vaccine") -@RequestScoped -public class VaccineManagedBean{ +//@RequestScoped +@ViewScoped +public class VaccineManagedBean implements Serializable{ + private static final long serialVersionUID = 1L; @EJB private VaccineService vaccineService; @@ -38,6 +42,27 @@ public class VaccineManagedBean{ vaccines = vaccineService.list(0, 100); } + private Vaccine selectedVaccine; // vacuna que vamos a editar + private String newName; // nuevo nombre para editar + + public Vaccine getSelectedVaccine() { return selectedVaccine; } + public void setSelectedVaccine(Vaccine selectedVaccine) { + this.selectedVaccine = selectedVaccine; + if (selectedVaccine != null) { + this.newName = selectedVaccine.getName(); // precarga el nombre actual + } + } + public String getNewName() { return newName; } + public void setNewName(String newName) { this.newName = newName; } + + public void editVaccine() { + if (selectedVaccine != null && newName != null && !newName.trim().isEmpty()) { + vaccineService.updateName(selectedVaccine.getId(), newName); + vaccines = vaccineService.list(0, 100); + selectedVaccine = null; + newName = null; + } + } private void clearForm() { name = null; diff --git a/jsf/src/main/webapp/vet/petDetails.xhtml b/jsf/src/main/webapp/vet/petDetails.xhtml index a68ebb44e536964a719166e26912615f55800604..50c2a0776e490dc9053fb293f9e266cfb9f3dec3 100644 --- a/jsf/src/main/webapp/vet/petDetails.xhtml +++ b/jsf/src/main/webapp/vet/petDetails.xhtml @@ -3,6 +3,7 @@ Detalle de Mascota @@ -38,9 +39,10 @@ - +

Registrar nueva vacunación

+ @@ -49,7 +51,7 @@ - + diff --git a/jsf/src/main/webapp/vet/vaccines.xhtml b/jsf/src/main/webapp/vet/vaccines.xhtml index 1f9c4a2def18c8bd64d11233d868e6987e832688..062d31b3b7684c1146fe3508b8b8e42dc8c90d13 100644 --- a/jsf/src/main/webapp/vet/vaccines.xhtml +++ b/jsf/src/main/webapp/vet/vaccines.xhtml @@ -36,6 +36,8 @@ + @@ -89,5 +91,20 @@
+ + + +

Editar vacuna #{vaccine.selectedVaccine.name}

+ + + + + + +
+ + +
+