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
6a37b255
Commit
6a37b255
authored
Oct 26, 2025
by
Breixo Senra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tabla de /owner/pets.xhtml con paginación
parent
a92ee916
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
154 additions
and
164 deletions
+154
-164
OwnerManagedBean.java
...src/main/java/es/uvigo/esei/xcs/jsf/OwnerManagedBean.java
+92
-106
PetManagedBean.java
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java
+12
-0
owners.xhtml
jsf/src/main/webapp/admin/owners.xhtml
+16
-25
pets.xhtml
jsf/src/main/webapp/owner/pets.xhtml
+20
-23
OwnerService.java
...src/main/java/es/uvigo/esei/xcs/service/OwnerService.java
+14
-10
No files found.
jsf/src/main/java/es/uvigo/esei/xcs/jsf/OwnerManagedBean.java
View file @
6a37b255
...
@@ -3,7 +3,9 @@ package es.uvigo.esei.xcs.jsf;
...
@@ -3,7 +3,9 @@ package es.uvigo.esei.xcs.jsf;
import
static
java
.
util
.
stream
.
Collectors
.
joining
;
import
static
java
.
util
.
stream
.
Collectors
.
joining
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
javax.annotation.PostConstruct
;
import
javax.enterprise.context.RequestScoped
;
import
javax.enterprise.context.RequestScoped
;
import
javax.faces.context.FacesContext
;
import
javax.faces.context.FacesContext
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
...
@@ -13,6 +15,10 @@ import es.uvigo.esei.xcs.domain.entities.Owner;
...
@@ -13,6 +15,10 @@ import es.uvigo.esei.xcs.domain.entities.Owner;
import
es.uvigo.esei.xcs.domain.entities.Pet
;
import
es.uvigo.esei.xcs.domain.entities.Pet
;
import
es.uvigo.esei.xcs.service.OwnerService
;
import
es.uvigo.esei.xcs.service.OwnerService
;
import
org.primefaces.model.LazyDataModel
;
import
org.primefaces.model.SortMeta
;
import
org.primefaces.model.FilterMeta
;
@Named
(
"owner"
)
@Named
(
"owner"
)
@RequestScoped
@RequestScoped
public
class
OwnerManagedBean
{
public
class
OwnerManagedBean
{
...
@@ -21,49 +27,41 @@ public class OwnerManagedBean {
...
@@ -21,49 +27,41 @@ public class OwnerManagedBean {
private
String
login
;
private
String
login
;
private
String
password
;
private
String
password
;
private
boolean
editing
;
private
boolean
editing
;
private
String
errorMessage
;
private
String
errorMessage
;
public
String
getLogin
()
{
private
LazyDataModel
<
Owner
>
owners
;
return
login
;
}
public
void
setLogin
(
String
name
)
{
this
.
login
=
name
;
}
public
String
getPassword
()
{
@PostConstruct
return
password
;
public
void
init
()
{
owners
=
new
LazyDataModel
<
Owner
>()
{
@Override
public
List
<
Owner
>
load
(
int
first
,
int
pageSize
,
Map
<
String
,
SortMeta
>
sortBy
,
Map
<
String
,
FilterMeta
>
filterBy
)
{
return
service
.
list
(
first
,
pageSize
);
}
}
public
void
setPassword
(
String
password
)
{
@Override
this
.
password
=
password
;
public
int
count
(
Map
<
String
,
FilterMeta
>
filterBy
)
{
return
service
.
countAll
();
}
}
};
public
String
getErrorMessage
()
{
return
errorMessage
;
}
public
boolean
isError
()
{
return
this
.
errorMessage
!=
null
;
}
public
boolean
isEditing
()
{
return
this
.
editing
;
}
}
public
void
setEditing
(
boolean
editing
)
{
public
LazyDataModel
<
Owner
>
getOwners
(
)
{
this
.
editing
=
editing
;
return
owners
;
}
}
public
List
<
Owner
>
getOwners
()
{
public
String
getLogin
()
{
return
login
;
}
return
this
.
service
.
list
(
0
,
100
);
public
void
setLogin
(
String
login
)
{
this
.
login
=
login
;
}
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
boolean
isEditing
()
{
return
editing
;
}
public
void
setEditing
(
boolean
editing
)
{
this
.
editing
=
editing
;
}
public
String
getErrorMessage
()
{
return
errorMessage
;
}
public
boolean
isError
()
{
return
errorMessage
!=
null
;
}
public
String
getPetNames
(
String
login
)
{
public
String
getPetNames
(
String
login
)
{
return
this
.
service
.
getPets
(
0
,
100
).
stream
()
return
this
.
service
.
getPets
(
login
,
0
,
100
).
stream
()
.
map
(
Pet:
:
getName
)
.
map
(
Pet:
:
getName
)
.
collect
(
joining
(
", "
));
.
collect
(
joining
(
", "
));
}
}
...
@@ -71,40 +69,33 @@ public class OwnerManagedBean {
...
@@ -71,40 +69,33 @@ public class OwnerManagedBean {
public
String
edit
(
String
login
)
{
public
String
edit
(
String
login
)
{
this
.
editing
=
true
;
this
.
editing
=
true
;
this
.
login
=
login
;
this
.
login
=
login
;
return
getViewId
();
return
this
.
getViewId
();
}
}
public
String
cancelEditing
()
{
public
String
cancelEditing
()
{
this
.
clear
();
clear
();
return
getViewId
();
return
this
.
getViewId
();
}
}
public
String
remove
(
String
login
)
{
public
String
remove
(
String
login
)
{
this
.
service
.
remove
(
login
);
service
.
remove
(
login
);
return
redirectTo
(
getViewId
());
return
redirectTo
(
this
.
getViewId
());
}
}
public
String
store
()
{
public
String
store
()
{
try
{
try
{
if
(
this
.
isEditing
())
{
if
(
isEditing
())
{
final
Owner
owner
=
this
.
service
.
get
(
this
.
login
);
Owner
owner
=
service
.
get
(
this
.
login
);
owner
.
changePassword
(
this
.
password
);
owner
.
changePassword
(
this
.
password
);
service
.
update
(
owner
);
this
.
service
.
update
(
owner
);
}
else
{
}
else
{
this
.
service
.
create
(
new
Owner
(
login
,
password
));
service
.
create
(
new
Owner
(
login
,
password
));
}
}
clear
();
this
.
clear
();
return
redirectTo
(
getViewId
());
return
redirectTo
(
this
.
getViewId
());
}
catch
(
Throwable
t
)
{
}
catch
(
Throwable
t
)
{
this
.
errorMessage
=
t
.
getMessage
();
this
.
errorMessage
=
t
.
getMessage
();
return
getViewId
();
return
this
.
getViewId
();
}
}
}
}
...
@@ -115,11 +106,6 @@ public class OwnerManagedBean {
...
@@ -115,11 +106,6 @@ public class OwnerManagedBean {
this
.
editing
=
false
;
this
.
editing
=
false
;
}
}
private
String
redirectTo
(
String
url
)
{
private
String
redirectTo
(
String
url
)
{
return
url
+
"?faces-redirect=true"
;
}
return
url
+
"?faces-redirect=true"
;
private
String
getViewId
()
{
return
FacesContext
.
getCurrentInstance
().
getViewRoot
().
getViewId
();
}
}
private
String
getViewId
()
{
return
FacesContext
.
getCurrentInstance
().
getViewRoot
().
getViewId
();
}
}
}
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java
View file @
6a37b255
...
@@ -53,6 +53,18 @@ public class PetManagedBean implements Serializable{
...
@@ -53,6 +53,18 @@ public class PetManagedBean implements Serializable{
public
int
count
(
Map
<
String
,
FilterMeta
>
filterBy
)
{
public
int
count
(
Map
<
String
,
FilterMeta
>
filterBy
)
{
return
service
.
countAll
();
return
service
.
countAll
();
}
}
@Override
public
String
getRowKey
(
Pet
pet
)
{
return
pet
.
getId
()
!=
null
?
pet
.
getId
().
toString
()
:
null
;
}
@Override
public
Pet
getRowData
(
String
rowKey
)
{
if
(
rowKey
==
null
)
return
null
;
return
service
.
get
(
Long
.
valueOf
(
rowKey
));
}
};
};
}
}
...
...
jsf/src/main/webapp/admin/owners.xhtml
View file @
6a37b255
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:p=
"http://primefaces.org/ui"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
xmlns:a=
"http://xmlns.jcp.org/jsf/passthrough"
>
xmlns:a=
"http://xmlns.jcp.org/jsf/passthrough"
>
...
@@ -31,30 +32,20 @@
...
@@ -31,30 +32,20 @@
</div>
</div>
</ui:define>
</ui:define>
<ui:define
name=
"content"
>
<ui:define
name=
"content"
>
<
h:dataTable
id=
"owners-table
"
<
p:dataTable
id=
"owners-table"
value=
"#{owner.owners}"
var=
"ownerEntity
"
value=
"#{owner.owners}"
var=
"ownerEntity
"
lazy=
"true"
paginator=
"true"
rows=
"10
"
styleClass=
"table table-striped table-bordered"
styleClass=
"table table-striped table-bordered"
columnClasses=
"owners-table-login,owners-table-password,owners-table-pets,owners-table-options"
columnClasses=
"owners-table-login,owners-table-password,owners-table-pets,owners-table-options"
>
>
<p:column
headerText=
"Login"
>
#{ownerEntity.login}
</p:column>
<h:column>
<p:column
headerText=
"Password"
>
#{ownerEntity.password}
</p:column>
<f:facet
name=
"header"
>
Login
</f:facet>
<p:column
headerText=
"Pets"
>
#{owner.getPetNames(ownerEntity.login)}
</p:column>
#{ownerEntity.login}
<p:column
headerText=
"Opciones"
>
</h:column>
<h:column>
<f:facet
name=
"header"
>
Password
</f:facet>
#{ownerEntity.password}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Pets
</f:facet>
#{owner.getPetNames(ownerEntity.login)}
</h:column>
<h:column>
<h:form>
<h:form>
<h:commandButton
class=
"owners-table-remove"
value=
"Remove"
action=
"#{owner.remove(ownerEntity.login)}"
/>
<h:commandButton
class=
"owners-table-remove"
value=
"Remove"
action=
"#{owner.remove(ownerEntity.login)}"
/>
<h:commandButton
class=
"owners-table-edit"
value=
"Edit"
action=
"#{owner.edit(ownerEntity.login)}"
/>
<h:commandButton
class=
"owners-table-edit"
value=
"Edit"
action=
"#{owner.edit(ownerEntity.login)}"
/>
</h:form>
</h:form>
</h
:column>
</p
:column>
</
h
:dataTable>
</
p
:dataTable>
</ui:define>
</ui:define>
</ui:composition>
</ui:composition>
</body>
</body>
...
...
jsf/src/main/webapp/owner/pets.xhtml
View file @
6a37b255
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:p=
"http://primefaces.org/ui"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
xmlns:a=
"http://xmlns.jcp.org/jsf/passthrough"
>
xmlns:a=
"http://xmlns.jcp.org/jsf/passthrough"
>
...
@@ -36,28 +37,24 @@
...
@@ -36,28 +37,24 @@
</div>
</div>
</ui:define>
</ui:define>
<ui:define
name=
"content"
>
<ui:define
name=
"content"
>
<h:dataTable
value=
"#{pet.pets}"
var=
"petEntity"
styleClass=
"table table-striped table-bordered"
>
<p:dataTable
id=
"pets-table"
value=
"#{pet.pets}"
var=
"petEntity"
<h:column>
paginator=
"true"
rows=
"10"
lazy=
"true"
<f:facet
name=
"header"
>
Name
</f:facet>
styleClass=
"table table-striped table-bordered"
>
#{petEntity.name}
<p:column
headerText=
"Name"
>
#{petEntity.name}
</p:column>
</h:column>
<p:column
headerText=
"Birth"
>
<h:column>
<f:facet
name=
"header"
>
Birth
</f:facet>
<h:outputText
value=
"#{petEntity.birth}"
>
<h:outputText
value=
"#{petEntity.birth}"
>
<f:convertDateTime
pattern=
"yyyy-M-d hh:mm:ss"
/>
<f:convertDateTime
pattern=
"yyyy-M-d hh:mm:ss"
/>
</h:outputText>
</h:outputText>
</h:column>
</p:column>
<h:column>
<p:column
headerText=
"Type"
>
#{petEntity.animal}
</p:column>
<f:facet
name=
"header"
>
Type
</f:facet>
<p:column
headerText=
"Opciones"
>
#{petEntity.animal}
</h:column>
<h:column>
<h:form>
<h:form>
<h:commandButton
value=
"Remove"
type=
"submit
"
action=
"#{pet.remove(petEntity.id)}"
/>
<h:commandButton
value=
"Remove
"
action=
"#{pet.remove(petEntity.id)}"
/>
<h:commandButton
value=
"Edit"
action=
"#{pet.edit(petEntity.id)}"
/>
<h:commandButton
value=
"Edit"
action=
"#{pet.edit(petEntity.id)}"
/>
</h:form>
</h:form>
</h:column>
</p:column>
</h:dataTable>
</p:dataTable>
</ui:define>
</ui:define>
</ui:composition>
</ui:composition>
</body>
</body>
...
...
service/src/main/java/es/uvigo/esei/xcs/service/OwnerService.java
View file @
6a37b255
...
@@ -35,6 +35,13 @@ public class OwnerService {
...
@@ -35,6 +35,13 @@ public class OwnerService {
private
Principal
currentUser
;
private
Principal
currentUser
;
public
int
countAll
()
{
Long
count
=
em
.
createQuery
(
"SELECT COUNT(o) FROM Owner o"
,
Long
.
class
)
.
getSingleResult
();
return
count
.
intValue
();
}
/**
/**
* Returns the owner identified by {@code login}. If there is no owner with
* Returns the owner identified by {@code login}. If there is no owner with
* the specified login, {@code null} will be returned.
* the specified login, {@code null} will be returned.
...
@@ -54,15 +61,12 @@ public class OwnerService {
...
@@ -54,15 +61,12 @@ public class OwnerService {
*
*
* @return the complete list of owners.
* @return the complete list of owners.
*/
*/
public
List
<
Owner
>
list
(
int
page
,
int
pageSize
)
{
public
List
<
Owner
>
list
(
int
first
,
int
pageSize
)
{
if
(
page
<
0
)
{
if
(
first
<
0
)
throw
new
IllegalArgumentException
(
"First can't be negative"
);
throw
new
IllegalArgumentException
(
"The page can't be negative"
);
if
(
pageSize
<=
0
)
throw
new
IllegalArgumentException
(
"Page size must be positive"
);
}
if
(
pageSize
<=
0
)
{
throw
new
IllegalArgumentException
(
"The page size can't be negative or zero"
);
}
return
em
.
createQuery
(
"SELECT o FROM Owner o"
,
Owner
.
class
)
return
em
.
createQuery
(
"SELECT o FROM Owner o"
,
Owner
.
class
)
.
setFirstResult
(
page
*
pageSize
)
.
setFirstResult
(
first
)
.
setMaxResults
(
pageSize
)
.
setMaxResults
(
pageSize
)
.
getResultList
();
.
getResultList
();
}
}
...
@@ -140,7 +144,7 @@ public class OwnerService {
...
@@ -140,7 +144,7 @@ public class OwnerService {
* @throws IllegalArgumentException if {@code login} is {@code null} or it
* @throws IllegalArgumentException if {@code login} is {@code null} or it
* does not identifies a valid owner.
* does not identifies a valid owner.
*/
*/
public
List
<
Pet
>
getPets
(
int
first
,
int
pageSize
)
{
public
List
<
Pet
>
getPets
(
String
login
,
int
first
,
int
pageSize
)
{
if
(
first
<
0
)
throw
new
IllegalArgumentException
(
"First can't be negative"
);
if
(
first
<
0
)
throw
new
IllegalArgumentException
(
"First can't be negative"
);
if
(
pageSize
<=
0
)
throw
new
IllegalArgumentException
(
"Page size must be positive"
);
if
(
pageSize
<=
0
)
throw
new
IllegalArgumentException
(
"Page size must be positive"
);
...
@@ -151,7 +155,7 @@ public class OwnerService {
...
@@ -151,7 +155,7 @@ public class OwnerService {
Pet
.
class
)
Pet
.
class
)
.
setFirstResult
(
first
)
.
setFirstResult
(
first
)
.
setMaxResults
(
pageSize
)
.
setMaxResults
(
pageSize
)
.
setParameter
(
"login"
,
currentUser
.
getName
()
)
.
setParameter
(
"login"
,
login
)
.
getResultList
();
.
getResultList
();
}
}
...
...
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