Commit fb006883 authored by Administrator's avatar Administrator

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.
parent f98e32e4
......@@ -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();
......
......@@ -32,26 +32,26 @@
</ui:define>
<ui:define name="content">
<h:dataTable id="owners-table"
value="#{owner.owners}" var="c"
value="#{owner.owners}" var="ownerEntity"
styleClass="table table-striped table-bordered"
columnClasses="owners-table-login,owners-table-password,owners-table-pets,owners-table-options"
>
<h:column>
<f:facet name="header">Login</f:facet>
#{c.login}
#{ownerEntity.login}
</h:column>
<h:column>
<f:facet name="header">Password</f:facet>
#{c.password}
#{ownerEntity.password}
</h:column>
<h:column>
<f:facet name="header">Pets</f:facet>
#{owner.getPetNames(c.login)}
#{owner.getPetNames(ownerEntity.login)}
</h:column>
<h:column>
<h:form>
<h:commandButton class="owners-table-remove" value="Remove" action="#{owner.remove(c.login)}"/>
<h:commandButton class="owners-table-edit" value="Edit" action="#{owner.edit(c.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:form>
</h:column>
</h:dataTable>
......
......@@ -36,25 +36,25 @@
</div>
</ui:define>
<ui:define name="content">
<h:dataTable value="#{pet.pets}" var="p" styleClass="table table-striped table-bordered">
<h:dataTable value="#{pet.pets}" var="petEntity" styleClass="table table-striped table-bordered">
<h:column>
<f:facet name="header">Name</f:facet>
#{p.name}
#{petEntity.name}
</h:column>
<h:column>
<f:facet name="header">Birth</f:facet>
<h:outputText value="#{p.birth}">
<h:outputText value="#{petEntity.birth}">
<f:convertDateTime pattern="yyyy-M-d hh:mm:ss" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">Type</f:facet>
#{p.animal}
#{petEntity.animal}
</h:column>
<h:column>
<h:form>
<h:commandButton value="Remove" type="submit" action="#{pet.remove(p.id)}"/>
<h:commandButton value="Edit" action="#{pet.edit(p)}"/>
<h:commandButton value="Remove" type="submit" action="#{pet.remove(petEntity.id)}"/>
<h:commandButton value="Edit" action="#{pet.edit(petEntity.id)}"/>
</h:form>
</h:column>
</h:dataTable>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment