Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bspastoriza19-esi-solutions
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Breixo Senra Pastoriza
bspastoriza19-esi-solutions
Commits
af0c608f
Commit
af0c608f
authored
Oct 25, 2025
by
Breixo Senra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Registro de nueva vacunacion con restricciones funcionando
parent
dc5935d4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
4 deletions
+95
-4
PetDetailsManagedBean.java
...ain/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java
+74
-4
petDetails.xhtml
jsf/src/main/webapp/vet/petDetails.xhtml
+21
-0
No files found.
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java
View file @
af0c608f
...
...
@@ -5,19 +5,43 @@ import javax.enterprise.context.RequestScoped;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
javax.faces.context.FacesContext
;
import
javax.faces.view.ViewScoped
;
import
java.util.Date
;
import
java.text.SimpleDateFormat
;
import
java.io.Serializable
;
import
java.text.ParseException
;
import
java.util.List
;
import
java.util.Map
;
import
es.uvigo.esei.xcs.domain.entities.Pet
;
import
es.uvigo.esei.xcs.domain.entities.Vaccine
;
import
es.uvigo.esei.xcs.domain.entities.Vaccination
;
import
es.uvigo.esei.xcs.service.PetService
;
import
es.uvigo.esei.xcs.service.VaccinationService
;
import
es.uvigo.esei.xcs.service.VaccineService
;
@Named
(
"petDetails"
)
@RequestScoped
public
class
PetDetailsManagedBean
{
//@RequestScoped
@ViewScoped
public
class
PetDetailsManagedBean
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Inject
private
PetService
petService
;
@Inject
private
VaccineService
vaccineService
;
@Inject
private
PetService
s
ervice
;
private
VaccinationService
vaccinationS
ervice
;
private
Pet
pet
;
private
Long
selectedVaccineId
;
private
String
vaccinationDate
;
// yyyy-MM-dd
private
List
<
Vaccine
>
allVaccines
;
@PostConstruct
public
void
init
()
{
Map
<
String
,
String
>
params
=
FacesContext
.
getCurrentInstance
()
...
...
@@ -25,11 +49,57 @@ public class PetDetailsManagedBean {
.
getRequestParameterMap
();
String
id
=
params
.
get
(
"id"
);
if
(
id
!=
null
)
{
this
.
pet
=
s
ervice
.
get
(
Long
.
parseLong
(
id
));
this
.
pet
=
petS
ervice
.
get
(
Long
.
parseLong
(
id
));
}
this
.
allVaccines
=
vaccineService
.
list
(
0
,
100
);
// ajustar paginación
}
public
Pet
getPet
()
{
return
pet
;
}
public
List
<
Vaccine
>
getAllVaccines
()
{
return
allVaccines
;
}
public
Long
getSelectedVaccineId
()
{
return
selectedVaccineId
;
}
public
void
setSelectedVaccineId
(
Long
selectedVaccineId
)
{
this
.
selectedVaccineId
=
selectedVaccineId
;
}
public
String
getVaccinationDate
()
{
return
vaccinationDate
;
}
public
void
setVaccinationDate
(
String
vaccinationDate
)
{
this
.
vaccinationDate
=
vaccinationDate
;
}
// Método para vacunar
public
String
vaccinate
()
{
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
);
// 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
)
{
FacesContext
.
getCurrentInstance
().
addMessage
(
null
,
new
javax
.
faces
.
application
.
FacesMessage
(
"Formato de fecha inválido"
));
}
catch
(
IllegalArgumentException
e
)
{
FacesContext
.
getCurrentInstance
().
addMessage
(
null
,
new
javax
.
faces
.
application
.
FacesMessage
(
e
.
getMessage
()));
}
return
null
;
// recargar la misma página
}
}
jsf/src/main/webapp/vet/petDetails.xhtml
View file @
af0c608f
...
...
@@ -37,6 +37,27 @@
#{v.vaccine.name}
</h:column>
</h:dataTable>
<h3>
Registrar nueva vacunación
</h3>
<h:form>
<h:panelGrid
columns=
"2"
>
<h:outputLabel
value=
"Vacuna:"
for=
"vaccine"
/>
<h:selectOneMenu
value=
"#{petDetails.selectedVaccineId}"
id=
"vaccine"
>
<f:selectItems
value=
"#{petDetails.allVaccines}"
var=
"v"
itemValue=
"#{v.id}"
itemLabel=
"#{v.name}"
/>
</h:selectOneMenu>
<h:outputLabel
value=
"Fecha:"
for=
"date"
/>
<h:inputText
value=
"#{petDetails.vaccinationDate}"
id=
"date"
placeholder=
"yyyy-MM-dd"
/>
<h:commandButton
value=
"Vacunar"
action=
"#{petDetails.vaccinate}"
/>
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</h:body>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment