1
I’m using Tomcat 7, Eclipse Juno (on Windows 7) and Primefaces 5 for my application.
After registering some information in the database (vaccines for vaccination booklet), access a screen (vaccine-booklet.xhtml) to view the status per patient of my system.
The fact is that when the Primefaces datagrid is loaded, it does not present the information in the same way that it is arranged in the Database (Mysql / JPA-Eclipselink). More specifically the field "dtPrevistaAplication".
And the curious thing is that after a Tomcat 7 RESTART, the values of this field are displayed correctly.
vaccine-booklet.xhtml
<?xml version='1.0' encoding='ISO-8859-1' ?>
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Caderneta de Vacinação - UBS+ Web</title>
</h:head>
<h:body>
<h:outputStylesheet library="css" name="ubs.css" />
<ui:include src="/WEB-INF/cabecalho.xhtml" />
<p:panel header="Caderneta de Vacinação">
<h:form id="frmCaderneta">
<br />
<h:outputLabel for="pacienteNome" value="Nome do Paciente: " />
<p:inputText id="pacienteNome" size="50"
value="#{vacinacaoBean.paciente.pessoa.nome}" readonly="TRUE" />
<p:commandButton icon="ui-icon-search" title="Visualizar"
onclick="PF('dlgPesqPaciente').show()">
</p:commandButton>
<p:spacer width="25" />
<br />
<br />
<p:commandButton value="Visualizar/Atualizar Caderneta"
action="#{vacinacaoBean.visualizaCaderneta}" update="vacina" />
<br />
<br />
<!-- DataGrid Vacinação -->
<p:dataGrid id="vacina" columns="6" var="vacinas" paginator="TRUE"
rowsPerPageTemplate="6,12,18"
value="#{vacinacaoBean.cadernetaVacinacao}">
<f:facet name="header">
Vacinas do Paciente
</f:facet>
<p:panel>
<p:panelGrid id="vacinaDose" columns="2">
<h:outputText value="Vacina: " />
<h:outputText value="#{vacinas.vacina.nome}" />
<h:outputText value="Data Prevista: " />
<h:outputText value="#{vacinas.dtPrevistaAplicacao}" >
<f:convertDateTime pattern="dd/MM/yyyy"/>
</h:outputText>
<h:outputText value="Dose: " />
<h:outputText value="#{vacinas.numDose}" />
<h:outputText value="Status: " />
<p:selectOneMenu id="status" value="#{vacinas.status}">
<f:selectItem itemLabel="Concluído" itemValue="Concluído" />
<f:selectItem itemLabel="Pendente" itemValue="Pendente" />
</p:selectOneMenu>
</p:panelGrid>
</p:panel>
</p:dataGrid>
</h:form>
<ui:include src="/WEB-INF/rodape.xhtml" />
</p:panel>
<!-- @Fellipe: Dialog de pesquisa do paciente -->
<p:dialog id="dlgPesqPaciente" widgetVar="dlgPesqPaciente" width="700"
header="Selecionar o Paciente" modal="TRUE" resizable="FALSE"
draggable="FALSE">
<h:form id="frmPesqPaciente">
<!-- Campo de Pesquisa -->
<p:outputLabel for="idnome" value="Pesquisar por Nome: " />
<p:inputText maxlenght="50" size="50" id="idnome" required="FALSE"
value="#{vacinacaoBean.nome}">
<p:ajax event="keyup"
listener="#{vacinacaoBean.findPacientePorNome}"
update="resultadoBusca" />
</p:inputText>
<br />
<br />
<!-- Tabela de Pessoas -->
<p:dataTable id="resultadoBusca"
value="#{vacinacaoBean.listaPaciente}" var="paciente"
selection="#{vacinacaoBean.paciente}" selectionMode="single"
rowKey="#{paciente.id}">
<p:column headerText="Nome" style="width:400px;text-align: center">
<h:outputText value="#{paciente.pessoa.nome}" />
</p:column>
<p:column headerText="Bairro" style="width:100px;text-align: center">
<h:outputText value="#{paciente.pessoa.bairro}" />
</p:column>
<p:column headerText="Código SUS"
style="width:100px;text-align: center">
<h:outputText value="#{paciente.cns}" />
</p:column>
<f:facet name="footer">
<p:commandButton value="Selecionar" update=":frmCaderneta"
onclick="PF('dlgPesqPaciente').close();"
action="#{vacinacaoBean.findPacientePorNome}">
</p:commandButton>
</f:facet>
</p:dataTable>
</h:form>
</p:dialog>
</h:body>
</html>
Vacinacaobean.java
package br.com.bean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import br.com.modelo.Paciente;
import br.com.modelo.Vacinacao;
import br.com.servico.VacinacaoServico;
@ManagedBean
@ViewScoped
public class VacinacaoBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Vacinacao vacinacao;
private Paciente paciente;
private String nome;
private List<Vacinacao> cadernetaVacinacao;
private List<Paciente> listaPaciente;
public VacinacaoBean() {
vacinacao = new Vacinacao();
paciente = new Paciente();
cadernetaVacinacao = new ArrayList<Vacinacao>();
listaPaciente = new ArrayList<Paciente>();
}
// Getters and Setters
public Vacinacao getVacinacao() {
return vacinacao;
}
public void setVacinacao(Vacinacao vacinacao) {
this.vacinacao = vacinacao;
}
public Paciente getPaciente() {
return paciente;
}
public void setPaciente(Paciente paciente) {
this.paciente = paciente;
}
public List<Paciente> getListaPaciente() {
return listaPaciente;
}
public void setListaPaciente(List<Paciente> listaPaciente) {
this.listaPaciente = listaPaciente;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public List<Vacinacao> getCadernetaVacinacao() {
return cadernetaVacinacao;
}
public void setCadernetaVacinacao(List<Vacinacao> cadernetaVacinacao) {
this.cadernetaVacinacao = cadernetaVacinacao;
}
// Métodos do Bean
public void findPacientePorNome() {
if (nome.equals("")) {
listaPaciente = null;
} else {
try {
listaPaciente = VacinacaoServico.getInstance()
.findPacientePorNome(nome);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void visualizaCaderneta() {
// Puxando dados de vacinação do Paciente
try {
cadernetaVacinacao = VacinacaoServico.getInstance()
.cadernetaDoPaciente(paciente.getId());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Vacinacao.java
package br.com.modelo;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@NamedQueries({
@NamedQuery(name = "Vacinacao.cadernetaDoPaciente", query = "SELECT v FROM Vacinacao v JOIN v.paciente p WHERE p.id = :idpaciente"),
@NamedQuery(name = "Vacinacao.findPacientePorNome", query = "SELECT c FROM Paciente c JOIN c.pessoa p WHERE p.nome LIKE :nome")
})
public class Vacinacao implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int codigo;
@Column(nullable=false)
private String status;
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable=true,name="DT_HR_APLICACAO")
private Date dtHrAplicacao;
@Temporal(TemporalType.DATE)
@Column(nullable=true,name="DT_PREVISTA_APLICACAO")
private Date dtPrevistaAplicacao;
@Column(nullable=false,name="NUM_DOSE")
private int numDose;
@Temporal(TemporalType.DATE)
@Column(nullable=true,name="PROXIMA_DOSE")
private Date proximaDose;
@ManyToOne
@JoinColumn(name="ID_ENFERMEIRO")
private Funcionario enfermeiro;
@ManyToOne
@JoinColumn(name="ID_PACIENTE")
private Paciente paciente;
@ManyToOne
@JoinColumn(name="ID_VACINA")
private Vacina vacina;
public int getCodigo() {
return codigo;
}
public void setCodigo(int codigo) {
this.codigo = codigo;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Date getDtHrAplicacao() {
return dtHrAplicacao;
}
public void setDtHrAplicacao(Date dtHrAplicacao) {
this.dtHrAplicacao = dtHrAplicacao;
}
public int getNumDose() {
return numDose;
}
public void setNumDose(int numDose) {
this.numDose = numDose;
}
public Date getProximaDose() {
return proximaDose;
}
public void setProximaDose(Date proximaDose) {
this.proximaDose = proximaDose;
}
public Paciente getPaciente() {
return paciente;
}
public void setPaciente(Paciente paciente) {
this.paciente = paciente;
}
public Vacina getVacina() {
return vacina;
}
public void setVacina(Vacina vacina) {
this.vacina = vacina;
}
public Funcionario getEnfermeiro() {
return enfermeiro;
}
public void setEnfermeiro(Funcionario enfermeiro) {
this.enfermeiro = enfermeiro;
}
public Date getDtPrevistaAplicacao() {
return dtPrevistaAplicacao;
}
public void setDtPrevistaAplicacao(Date dtPrevistaAplicacao) {
this.dtPrevistaAplicacao = dtPrevistaAplicacao;
}
}
Remembering that it is not feasible for an application in Production a re-start of the application server all the time =)
In the database what is the format of the column? Timestamp?
– Gustavo Cinque
I could also put the class
Vacinacao
?– Gustavo Cinque
@Gustavocinque, added the class. Yes, it’s TIMESTAMP.
– Fellipe Soares
Sorry for the delay, I couldn’t get back to that question during the weekend. It seems to me that there is some kind of mistake in time to pass the
TIMESTAMP
table for the objectDate dtPrevistaAplicacao
. According to the documentation itself: The Timestamp.equals(Object) method Never Returns true when passed an Object that isn’t an instance of java.sql.Timestamp, because the nanos Component of a date is Unknown.... Maybe changing the table ofTIMESTAMP
forDATE
work.– Gustavo Cinque
@Gustavocinque, I discovered the problem. In reality the problem was in the generation of the data, which happened in another Managedbean, where in this one the manipulation of the date/time were being carried out using objects of type Date. I directed them to switch to Calendar, since Date has deprecated functions, and the problem has been solved.
– Fellipe Soares