@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: 1
Participantes: 1