Created
May 26, 2021 22:47
-
-
Save Marlysson/4054f9e268434dd8c7950a3b11abbb9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:p="http://primefaces.org/ui" | |
xmlns:h="http://xmlns.jcp.org/jsf/html" | |
xmlns:f="http://xmlns.jcp.org/jsf/core"> | |
<h:head> | |
<title>Cadastro de Vacinas</title> | |
</h:head> | |
<h:body> | |
<h:form id="formulario"> | |
<p:staticMessage severity="info" summary="Quantidade de vacinas:" | |
detail="#{vacinaBean.lista.size}" style="width: 100%" /> | |
<p:dataTable value="#{vacinaBean.lista}" var="c"> | |
<p:column> | |
<f:facet name="header">Id</f:facet> | |
<p:outputLabel value="#{c.id}" /> | |
</p:column> | |
<p:column> | |
<f:facet name="header">Tipo de Vacina</f:facet> | |
<p:outputLabel value="#{c.tipodevacina}" /> | |
</p:column> | |
<p:column> | |
<f:facet name="header">Quantidade</f:facet> | |
<p:outputLabel value="#{c.quantidade}" /> | |
</p:column> | |
</p:dataTable> | |
</h:form> | |
<p:link outcome="index" value="voltar" /> | |
</h:body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bean; | |
import javax.faces.application.FacesMessage; | |
import javax.faces.context.FacesContext; | |
import dao.VacinaDao; | |
import entidades.Vacina; | |
import java.util.List; | |
import javax.faces.bean.ManagedBean; | |
import dao.VacinaDao; | |
@ManagedBean | |
public class VacinaBean { | |
private Vacina vacina = new Vacina(); | |
private List<Vacina> lista; | |
private int quantidade; | |
// Iniciei o array | |
public VacinaBean(){ | |
this.lista = new ArrayList<>(); | |
} | |
public String salvar() { | |
VacinaDao.salvar(vacina); | |
vacina = new Vacina(); | |
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Sucesso", "Vacina salva com sucesso!")); | |
// Depois que insere recupera novamente do banco. | |
this.lista = VacinaDao.listar(); | |
return null; | |
} | |
public Vacina getVacina() { | |
return vacina; | |
} | |
public void setVacina(Vacina vacina) { | |
this.vacina = vacina; | |
} | |
public void setLista(List<Vacina> lista) { | |
this.lista = lista; | |
} | |
public int getQuantidade() { | |
return quantidade; | |
} | |
public void setQuantidade(int quantidade) { | |
this.quantidade = quantidade; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment