Quantcast
Channel: GUJ - Tópicos com a tag hibernate
Viewing all articles
Browse latest Browse all 759

Dialog em Datatable no JSF exibindo dados errados

$
0
0

@Douglas_Cunha escreveu:

Pessoal,
Possuo um projeto pequeno apenas para exibir algumas informações de chamadas telefonicas aqui onde trabalho. O que preciso é basicamente acessar uma base de dados, exibir algumas informações primarias numa tabela e em cada linha da tabela exibir um link para abrir um dialog contendo o restante das informações daquela linha especifica, porém tenho enfrentado alguns problemas. Até ao ponto de exibir as informações basicas está ok, porém quando crio meu commandlink para chamar o dialog passando a linha selecionada, ele seleciona um valor totalmente diferente do que eu estava buscando.

Exemplo:

Na imagem está minha pagina. O dialog deveria mostrar exatamente o mesmo valor da minha tabela, porém ele está buscando de outra posição de outro registro.

Abaixo ta minhas classes, provavelmente esteja errando em algum fluxo do código.

Call.Java
package projeto.gravacoes.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name="Calls")
public class Call {
    @Id
    @Column(unique=true)
    private int id;
    @Column(name="callId")
    private String callId;
    @Column(name="originalCallId")
    private String originalCallId;
    @Column(name="routeCode")
    private String routeCode;
    @Column(name="channel")
    private String channel;
    @Column(name="groupCode")
    private String groupCode;
    private String loginId;
    private String ani;
    private String originalDestination;
    private String destination;
    private String uui;
    private String callType;
    @Temporal(TemporalType.TIME)
    private Date duration;
    private String result;
    private String cause;
    private String progressIndicator;
    @Temporal(TemporalType.TIMESTAMP)
    private Date start;
    @Temporal(TemporalType.TIMESTAMP)
    private Date answer;
    @Temporal(TemporalType.TIMESTAMP)
    private Date end;
    private String recordingFilename;
    @Column(columnDefinition = "TINYINT(3)")
    private Boolean exported;
    private String serverName;
    @Column(columnDefinition = "TINYINT(3)")
    private Boolean recordingConverted;
    @Temporal(TemporalType.TIME)
    private Date agentIdleTime;
    @Column(columnDefinition = "TINYINT(3)")
    private Boolean queued;
    private String disconnectionSource;
    @Transient
    private String routeName;
    
   //GETTERS AND SETTERS
}

CallDAO.Java:

package projeto.gravacoes.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import projeto.gravacoes.model.Call;
import projeto.gravacoes.utils.JPAUtils;

public class CallDAO {

    public Call retrieveCallById(int idCall){
        Call call = null;
        EntityManager em = new JPAUtils().getEntityManager();
        Query q = em.createQuery("select c from Call c where id = :idCall", Call.class).setParameter("idCall", idCall);
        call = (Call) q.getSingleResult();
        JPAUtils.closeEntityManager(em);
        return call;
    }

    @SuppressWarnings("unchecked")
    public List<Call> retrieveAllCalls(){
        List<Call> calls = null;
        EntityManager entityManager = new JPAUtils().getEntityManager();
        Query q = entityManager.createQuery("SELECT c FROM Call c order by start desc",Call.class).setMaxResults(100);
        calls = q.getResultList();
        JPAUtils.closeEntityManager(entityManager);
        return calls;
    }

}

CallMB.java

package projeto.gravacoes.controller;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.view.ViewScoped;

import projeto.gravacoes.dao.CallDAO;
import projeto.gravacoes.dao.RouteDAO;
import projeto.gravacoes.model.Call;

@ManagedBean
@ViewScoped
public class CallMB {

    private List<Call> allCalls;
    private Call selectedCall;

    
    public Call getSelectedCall() {
        System.out.println("Passou pelo getSelectedCall");
        return selectedCall;
    }
    public void setSelectedCall(Call selectedCall) {
        System.out.println("Passou pelo setSelectedCall: "+ selectedCall.getCallId());
        this.selectedCall = selectedCall;
    }

    public List<Call> getAllCalls() {
        allCalls = new CallDAO().retrieveAllCalls();
        RouteDAO routeDAO = new RouteDAO();
        for (Call call : allCalls) {
            call.setRouteName(routeDAO.retrieveRouteByCode(call.getRouteCode()).getName());
        }
        return allCalls;
    }
}

E finalmente minha index contendo meu Datatable:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:c="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Parla! - Consulta de Chamadas</title>
    <link rel="stylesheet" type="text/css" href="assets/css/style.css" />
</h:head>
<h:body>

    <ui:composition template="template/_template.xhtml">
        <ui:define name="content">
            <h:form id="form">

                <p:dataTable id="calls" var="call" value="#{callMB.allCalls}">

                    <p:column headerText="Info" width="200" style="text-align: center">
                        
                        <p:commandLink value="Informações" oncomplete="PF('modalCall').show()" update=":form:dialog">
                            <c:setPropertyActionListener target="#{callMB.selectedCall}" value="#{call}" />
                        </p:commandLink>

                    </p:column>

                    <p:column headerText="Call ID">
                        <h:outputText value="#{call.callId}"></h:outputText>
                    </p:column>


                </p:dataTable>

                <p:dialog modal="true" width="500" height="500" widgetVar="modalCall" id="dialog">
                    <h:outputText value="#{callMB.selectedCall.callId}"></h:outputText>
                </p:dialog>


            </h:form>
        </ui:define>
    </ui:composition>

</h:body>
</html>

Mensagens: 2

Participantes: 1

Ler tópico completo


Viewing all articles
Browse latest Browse all 759

Trending Articles


Vimeo 10.7.1 by Vimeo.com, Inc.


UPDATE SC IDOL: TWO BECOME ONE


KASAMBAHAY BILL IN THE HOUSE


Girasoles para colorear


Presence Quotes – Positive Quotes


EASY COME, EASY GO


Love with Heart Breaking Quotes


Re:Mutton Pies (lleechef)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 10.7.0 by Vimeo.com, Inc.


FORECLOSURE OF REAL ESTATE MORTGAGE


FORTUITOUS EVENT


Pokemon para colorear


Sapos para colorear


Smile Quotes


Letting Go Quotes


Love Song lyrics that marks your Heart


RE: Mutton Pies (frankie241)


Hato lada ym dei namar ka jingpyrshah jong U JJM Nichols Roy (Bah Joy) ngin...


Long Distance Relationship Tagalog Love Quotes



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>