OutputText only refreshes after Tomcat Restart

1

I'm using Tomcat 7, Eclipse Juno (in Windows 7) and Primefaces 5 for my application.

After registering some information in the database (vaccines for vaccination book), access a screen (vaccine-caderneta.xhtml) to view the status per patient of my system.

The fact is that when the PrimeFaces dataGrid is loaded, it does not display the information in the same way that it is arranged in the Database (MySQL / JPA-EclipseLink). More specifically, the "dtPrevistaApplication" field.

And the most curious thing is that after a Tomcat 7 RESTART, the values in this field are displayed correctly.

vaccine-caderneta.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>

VaccinacaoBean.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();
        }
    }
}

Vaccinacao.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 impractical for an application in Production to restart the application server all the time =)

    
asked by anonymous 21.11.2014 / 13:05

1 answer

1

I found a solution to the problem.

I identified that in reality the problem only occurred when the dtPrevistaAplicacao attribute of the Vacinacao.java class was being sent to the database with an object of type java.util.Date , while manipulating the data within a ManagedBean. >

So, in the GET method that JSF uses to populate the rendered component of Primefaces on the screen, it repeats the value for all lines of dataTable or dataGrid .

Using objects of type Calendar , which is by far the most recommended, the problem has been solved. Using java.sql.Date is also an option.

    
24.11.2014 / 17:34