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