From fb0068832e42a1c30e19a09477fbc5ee61fe121a Mon Sep 17 00:00:00 2001 From: Miguel Reboiro-Jato Date: Tue, 16 Oct 2018 16:47:01 +0200 Subject: [PATCH] Changes pet list to edit by id instead of entity The pet list "Edit" button was calling a method in the managed bean that received the Pet entity. This caused lots of unnecessary queries in the database. In order to avoid this, the edit method now receives the pet identifier instead of the entity. --- .../java/es/uvigo/esei/xcs/jsf/PetManagedBean.java | 4 +++- jsf/src/main/webapp/admin/owners.xhtml | 12 ++++++------ jsf/src/main/webapp/owner/pets.xhtml | 12 ++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java index 2af4579..933c67f 100644 --- a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java +++ b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java @@ -77,7 +77,9 @@ public class PetManagedBean { return this.service.list(); } - public String edit(Pet pet) { + public String edit(int petId) { + final Pet pet = this.service.get(petId); + this.id = pet.getId(); this.name = pet.getName(); this.birth = pet.getBirth(); diff --git a/jsf/src/main/webapp/admin/owners.xhtml b/jsf/src/main/webapp/admin/owners.xhtml index 55e5e89..050be53 100644 --- a/jsf/src/main/webapp/admin/owners.xhtml +++ b/jsf/src/main/webapp/admin/owners.xhtml @@ -32,26 +32,26 @@ Login - #{c.login} + #{ownerEntity.login} Password - #{c.password} + #{ownerEntity.password} Pets - #{owner.getPetNames(c.login)} + #{owner.getPetNames(ownerEntity.login)} - - + + diff --git a/jsf/src/main/webapp/owner/pets.xhtml b/jsf/src/main/webapp/owner/pets.xhtml index 78a06a3..489e0aa 100644 --- a/jsf/src/main/webapp/owner/pets.xhtml +++ b/jsf/src/main/webapp/owner/pets.xhtml @@ -36,25 +36,25 @@ - + Name - #{p.name} + #{petEntity.name} Birth - + Type - #{p.animal} + #{petEntity.animal} - - + + -- 2.18.1