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
d596a8e3
Commit
d596a8e3
authored
Oct 25, 2025
by
Breixo Senra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Paginación funcionando
parent
25685e70
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
39 deletions
+86
-39
PetDetailsManagedBean.java
...ain/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java
+16
-14
PetManagedBean.java
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java
+38
-4
petDetails.xhtml
jsf/src/main/webapp/vet/petDetails.xhtml
+2
-1
pets.xhtml
jsf/src/main/webapp/vet/pets.xhtml
+12
-19
PetService.java
...e/src/main/java/es/uvigo/esei/xcs/service/PetService.java
+18
-1
No files found.
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java
View file @
d596a8e3
package
es
.
uvigo
.
esei
.
xcs
.
jsf
;
import
javax.annotation.PostConstruct
;
import
javax.ejb.EJBException
;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
javax.faces.application.FacesMessage
;
import
javax.faces.context.FacesContext
;
import
javax.faces.view.ViewScoped
;
...
...
@@ -50,7 +52,7 @@ public class PetDetailsManagedBean implements Serializable{
if
(
id
!=
null
)
{
this
.
pet
=
petService
.
get
(
Long
.
parseLong
(
id
));
}
this
.
allVaccines
=
vaccineService
.
list
(
0
,
100
);
// ajustar paginación
this
.
allVaccines
=
vaccineService
.
list
(
0
,
100
);
}
public
Pet
getPet
()
{
...
...
@@ -77,28 +79,28 @@ public class PetDetailsManagedBean implements Serializable{
this
.
vaccinationDate
=
vaccinationDate
;
}
// Método para vacunar
public
String
vaccinate
()
{
if
(
selectedVaccineId
==
null
||
vaccinationDate
==
null
/*|| vaccinationDate.isEmpty()*/
)
{
if
(
selectedVaccineId
==
null
||
vaccinationDate
==
null
)
{
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
,
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) {
new
FacesMessage
(
"Vacunación creada correctamente"
));
}
catch
(
EJBException
e
)
{
Throwable
cause
=
e
.
getCause
();
if
(
cause
instanceof
IllegalArgumentException
)
{
FacesContext
.
getCurrentInstance
().
addMessage
(
null
,
new javax.faces.application.FacesMessage("Formato de fecha inválido"
));
}*/
catch
(
IllegalArgumentException
e
)
{
new
FacesMessage
(
cause
.
getMessage
()
));
}
else
{
FacesContext
.
getCurrentInstance
().
addMessage
(
null
,
new
javax
.
faces
.
application
.
FacesMessage
(
e
.
getMessage
()
));
new
FacesMessage
(
"Error inesperado al crear vacunación"
));
}
return
null
;
// recargar la misma página
}
return
null
;
}
}
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java
View file @
d596a8e3
package
es
.
uvigo
.
esei
.
xcs
.
jsf
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
javax.annotation.PostConstruct
;
import
javax.enterprise.context.RequestScoped
;
import
javax.faces.context.FacesContext
;
import
javax.faces.view.ViewScoped
;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
org.primefaces.model.FilterMeta
;
import
org.primefaces.model.LazyDataModel
;
import
org.primefaces.model.SortMeta
;
import
es.uvigo.esei.xcs.domain.entities.AnimalType
;
import
es.uvigo.esei.xcs.domain.entities.Pet
;
import
es.uvigo.esei.xcs.service.PetService
;
@Named
(
"pet"
)
@RequestScoped
public
class
PetManagedBean
{
//@RequestScoped
@ViewScoped
public
class
PetManagedBean
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Inject
private
PetService
service
;
...
...
@@ -27,6 +38,29 @@ public class PetManagedBean {
private
String
errorMessage
;
private
LazyDataModel
<
Pet
>
pets
;
@PostConstruct
public
void
init
()
{
pets
=
new
LazyDataModel
<
Pet
>()
{
@Override
public
List
<
Pet
>
load
(
int
first
,
int
pageSize
,
Map
<
String
,
SortMeta
>
sortBy
,
Map
<
String
,
FilterMeta
>
filterBy
)
{
return
service
.
getAll
(
first
,
pageSize
);
}
@Override
public
int
count
(
Map
<
String
,
FilterMeta
>
filterBy
)
{
return
service
.
countAll
();
}
};
}
public
LazyDataModel
<
Pet
>
getPets
()
{
return
pets
;
}
public
String
getName
()
{
return
name
;
}
...
...
@@ -73,11 +107,11 @@ public class PetManagedBean {
this
.
id
=
id
;
}
public
List
<
Pet
>
getPets
()
{
/*
public List<Pet> getPets() {
List<Pet> list = this.service.getAll(0, 100);
System.out.println(list);
return list;
}
}
*/
public
String
edit
(
Long
petId
)
{
final
Pet
pet
=
this
.
service
.
get
(
petId
);
...
...
jsf/src/main/webapp/vet/petDetails.xhtml
View file @
d596a8e3
...
...
@@ -42,7 +42,8 @@
<p:commandButton
value=
"Open Dialog"
/>
<h3>
Registrar nueva vacunación
</h3>
<h:form>
<!--<h:messages globalOnly="true" layout="table" style="color:red;" />-->
<h:messages
globalOnly=
"true"
style=
"color:red;"
/>
<h:panelGrid
columns=
"2"
>
<h:outputLabel
value=
"Vacuna:"
for=
"vaccine"
/>
<h:selectOneMenu
value=
"#{petDetails.selectedVaccineId}"
id=
"vaccine"
>
...
...
jsf/src/main/webapp/vet/pets.xhtml
View file @
d596a8e3
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:p=
"http://primefaces.org/ui"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
>
<h:head>
<title>
Mis Mascotas
</title>
</h:head>
<h:body>
<h:form>
<h:dataTable
value=
"#{pet.pets}"
var=
"p"
border=
"1"
>
<h:column>
<f:facet
name=
"header"
>
Nombre
</f:facet>
#{p.name}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Nacimiento
</f:facet>
#{p.birth}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Tipo
</f:facet>
#{p.animal}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Acción
</f:facet>
<h:commandButton
value=
"#{pet.isAssignedToMe(p) ? 'Desasignar' : 'Asignar'}"
action=
"#{pet.toggleAssignment(p)}"
/>
</h:column>
</h:dataTable>
<!--NUEVA TABLA-->
<p:dataTable
value=
"#{pet.pets}"
var=
"p"
paginator=
"true"
rows=
"10"
lazy=
"true"
>
<p:column
headerText=
"Nombre"
>
#{p.name}
</p:column>
<p:column
headerText=
"Nacimiento"
>
#{p.birth}
</p:column>
<p:column
headerText=
"Tipo"
>
#{p.animal}
</p:column>
<p:column
headerText=
"Acción"
>
<p:commandButton
value=
"#{pet.isAssignedToMe(p) ? 'Desasignar' : 'Asignar'}"
action=
"#{pet.toggleAssignment(p)}"
update=
"@this"
/>
</p:column>
</p:dataTable>
<h:messages
globalOnly=
"true"
/>
</h:form>
...
...
service/src/main/java/es/uvigo/esei/xcs/service/PetService.java
View file @
d596a8e3
...
...
@@ -55,12 +55,18 @@ public class PetService {
throw new EJBAccessException("Pet's owner is not the current principal");
}
}*/
public
int
countAll
()
{
Long
count
=
em
.
createQuery
(
"SELECT COUNT(p) FROM Pet p"
,
Long
.
class
)
.
getSingleResult
();
return
count
.
intValue
();
}
public
Pet
get
(
Long
id
)
{
return
em
.
find
(
Pet
.
class
,
id
);
}
public
List
<
Pet
>
getAll
(
int
page
,
int
pageSize
)
{
/*
public List<Pet> getAll(int page, int pageSize) {
if (page < 0) {
throw new IllegalArgumentException("The page can't be negative");
}
...
...
@@ -71,9 +77,20 @@ public class PetService {
.setFirstResult(page * pageSize)
.setMaxResults(pageSize)
.getResultList();
}*/
public
List
<
Pet
>
getAll
(
int
first
,
int
pageSize
)
{
if
(
first
<
0
)
throw
new
IllegalArgumentException
(
"First can't be negative"
);
if
(
pageSize
<=
0
)
throw
new
IllegalArgumentException
(
"Page size must be positive"
);
return
em
.
createQuery
(
"SELECT p FROM Pet p"
,
Pet
.
class
)
.
setFirstResult
(
first
)
// no multiplicar por pageSize
.
setMaxResults
(
pageSize
)
.
getResultList
();
}
/**
* Returns the complete list of pets of the current owner.
*
...
...
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