Commit d1c1cdba authored by Breixo Senra's avatar Breixo Senra

Insercion de Mascotas con fecha actual

parent 6a37b255
......@@ -7,10 +7,10 @@ import java.util.Map;
import java.util.Optional;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
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;
......@@ -27,7 +27,7 @@ import es.uvigo.esei.xcs.service.PetService;
public class PetManagedBean implements Serializable{
private static final long serialVersionUID = 1L;
@Inject
@EJB
private PetService service;
private String name;
......@@ -159,6 +159,7 @@ public class PetManagedBean implements Serializable{
this.service.update(pet);
} else {
//this.service.create(new Pet(name, animal, birth));
this.service.createPet(name, animal, new Date());
}
this.clear();
......
......@@ -2,60 +2,59 @@
<!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"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
<head>
<title>Pet Store - Pets</title>
</head>
<body>
<ui:composition template="../WEB-INF/template.xhtml">
<ui:define name="jumbotron">
<h2>New Pet</h2>
<h:panelGroup class="row">
<h:form>
<h:inputText class="form-control" a:placeholder="Pet name" value="#{pet.name}"></h:inputText>
<h:inputText value="#{pet.birth}" size="20" required="true" label="Receipt Date" class="form-control" a:placeholder="Birth (YYYY-MM-DD hh:mm:ss)">
<f:convertDateTime pattern="yyyy-M-d hh:mm:ss" />
</h:inputText>
<h:selectOneMenu value="#{pet.animal}" class="form-control">
<f:selectItem itemValue="BIRD" itemLabel="Bird" />
<f:selectItem itemValue="CAT" itemLabel="Cat" />
<f:selectItem itemValue="DOG" itemLabel="Dog" />
</h:selectOneMenu>
<h:inputHidden value="#{pet.id}"></h:inputHidden>
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
<head>
<title>Pet Store - Pets</title>
</head>
<body>
<ui:composition template="../WEB-INF/template.xhtml">
<ui:define name="jumbotron">
<h2>New Pet</h2>
<h:messages globalOnly="false" />
<h:form id="mainForm">
<h:panelGroup class="row">
<h:inputText class="form-control" a:placeholder="Pet name" value="#{pet.name}" />
<!--<h:inputText value="#{pet.birth}" size="20" label="Receipt Date" class="form-control" a:placeholder="Birth (YYYY-MM-DD hh:mm:ss)">
<f:convertDateTime pattern="yyyy-M-d hh:mm:ss" />
</h:inputText>-->
<h:selectOneMenu value="#{pet.animal}" class="form-control">
<f:selectItem itemValue="BIRD" itemLabel="Bird" />
<f:selectItem itemValue="CAT" itemLabel="Cat" />
<f:selectItem itemValue="DOG" itemLabel="Dog" />
</h:selectOneMenu>
<h:inputHidden value="#{pet.id}" />
<h:commandButton id="submit" class="btn btn-default" value="Store" action="#{pet.store()}" />
<h:commandButton id="cancel" class="btn btn-default" value="Cancel" action="#{pet.cancelEditing()}" />
</h:form>
</h:panelGroup>
<div class="row">
<h:panelGroup class="alert alert-danger" role="alert" rendered="#{pet.error}">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
Error: #{pet.errorMessage}
</h:panelGroup>
</div>
</ui:define>
<ui:define name="content">
<p:dataTable id="pets-table" value="#{pet.pets}" var="petEntity"
paginator="true" rows="10" lazy="true"
styleClass="table table-striped table-bordered">
<p:column headerText="Name">#{petEntity.name}</p:column>
<p:column headerText="Birth">
<h:outputText value="#{petEntity.birth}">
<f:convertDateTime pattern="yyyy-M-d hh:mm:ss" />
</h:outputText>
</p:column>
<p:column headerText="Type">#{petEntity.animal}</p:column>
<p:column headerText="Opciones">
<h:form>
<h:commandButton value="Remove" action="#{pet.remove(petEntity.id)}"/>
<h:commandButton value="Edit" action="#{pet.edit(petEntity.id)}"/>
</h:form>
</p:column>
</p:dataTable>
<h:commandButton id="cancel" class="btn btn-default" value="Cancel" action="#{pet.cancelEditing()}"/>
</h:panelGroup>
<div class="row">
<h:panelGroup class="alert alert-danger" role="alert" rendered="#{pet.error}">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
Error: #{pet.errorMessage}
</h:panelGroup>
</div>
</ui:define>
</ui:composition>
</body>
</html>
\ No newline at end of file
<p:dataTable id="pets-table" value="#{pet.pets}" var="petEntity"
paginator="true" rows="10" lazy="true"
styleClass="table table-striped table-bordered">
<p:column headerText="Name">#{petEntity.name}</p:column>
<p:column headerText="Birth">
<h:outputText value="#{petEntity.birth}">
<f:convertDateTime pattern="yyyy-M-d hh:mm:ss" />
</h:outputText>
</p:column>
<p:column headerText="Type">#{petEntity.animal}</p:column>
<p:column headerText="Opciones">
<p:commandButton value="Remove" action="#{pet.remove(petEntity.id)}" process="@this" update="@form" />
<p:commandButton value="Edit" action="#{pet.edit(petEntity.id)}" process="@this" update="@form" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
......@@ -4,6 +4,7 @@ import static java.util.Objects.requireNonNull;
import java.io.Console;
import java.security.Principal;
import java.util.Date;
import java.util.List;
import javax.annotation.security.PermitAll;
......@@ -15,6 +16,7 @@ import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import es.uvigo.esei.xcs.domain.entities.AnimalType;
import es.uvigo.esei.xcs.domain.entities.Owner;
import es.uvigo.esei.xcs.domain.entities.Pet;
import es.uvigo.esei.xcs.domain.entities.Vaccination;
......@@ -142,6 +144,14 @@ public class PetService {
}
}
public Pet createPet(String name, AnimalType animal, Date birth) {
Owner owner = em.find(Owner.class, currentUser.getName());
Pet pet = new Pet(name, animal, birth, owner);
this.em.persist(pet);
return pet;
}
/**
* Updates the information of a pet. If the pet is not stored, it will be
* created.
......
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