Boa tarde, pessoal.
Procurei em vários foruns e não encontrei uma solução para meu problema.
Tenho um formulário com uma dataTeble onde eu filtro os valores da tabela e clico em um botão da coluna para abrir um fialog com um formulário onde eu altero os dados da linha em que eu cliquei.
O que acontece é que o dialog abre e não carrega os dados no formuario.
Segue os código.
Tabela de dados
[code]<?xml version="1.0" encoding="ISO-8859-1" ?>
Agenda de Cadastro de Demandas<h:outputScript name="locale-primefaces.js" library="js" />
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<script>
$(function() {
$("#tabs").tabs();
});
</script>
</h:head>
<h:body>
<div id="tabs"
style="width: 1040px; float: center; border: solid 1px #DFDFDF; margin: 10px auto; top: 150px; left: 0px; background: white; padding: 0px; font-size: 0.8em"
class="ui-widget-content ui-corner-bottom ui-corner-top ui-helper-clearfix ui-shadow">
<ul>
<li><a href="#tabs-1">Cadastrar</a></li>
<li><a href="#tabs-2">Consultar/Alterar</a></li>
</ul>
<div id="tabs-1">
<div id="tabs-2"
style="width: 1000px; float: center; border: solid 1px #DFDFDF; margin: 10px auto; top: 20px; left: 0px; background: white; padding: 0px;"
class="ui-widget-content ui-corner-bottom ui-corner-top ui-helper-clearfix ui-shadow">
<h:form id="formConsultar">
<p:dataTable id="tabDemandas2" var="td2"
value="#{demanda.listaDemandaCompleta}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'even-row' : 'odd-row'}"
rowIndexVar="rowIx" paginator="true" rows="15"
style="margin-bottom:20px" resizableColumns="true"
rowsPerPageTemplate="5,10,15,20,40"
emptyMessage="Nenhum relatório encontrado" rowKey="#{td2.id}"
selectionMode="single"
filteredValue="#{demanda.filteredListaDemandaCompleta}">
<p:column headerText="" width="23" styleClass="wrap">
<p:commandButton icon="ui-icon ui-icon-pencil" type="button"
onclick="PF('dlgAltDemanda').show();">
<f:setPropertyActionListener
target="#{demanda.demandaSelecionada}" value="#{td2}" />
</p:commandButton>
</p:column>
<p:column headerText="Id" width="40" rendered="false">
<h:outputText value="#{td2.id}" />
</p:column>
<p:column headerText="IdGerente" width="40" rendered="false">
<h:outputText value="#{td2.idGerente}" />
</p:column>
<p:column headerText="IdAssessor" width="40" rendered="false">
<h:outputText value="#{td2.idAssessor}" />
</p:column>
<p:column headerText="Início" width="60" resizable="true"
filterBy="#{td2.dataInicio}" filterMatchMode="contains"
filterStyle="max-width: 50px">
<h:outputText value="#{td2.dataInicio}">
<f:convertDateTime locale="pt_BR" />
</h:outputText>
</p:column>
<p:column headerText="Atend." width="60" resizable="true"
filterBy="#{td2.dataAtendimento}" filterMatchMode="contains"
filterStyle="max-width: 50px">
<h:outputText value="#{td2.dataAtendimento}">
<f:convertDateTime locale="pt_BR" />
</h:outputText>
</p:column>
<p:column headerText="Venc." width="60" resizable="true"
filterBy="#{td2.dataVencimento}" filterMatchMode="contains"
filterStyle="max-width: 50px">
<h:outputText value="#{td2.dataVencimento}">
<f:convertDateTime locale="pt_BR" />
</h:outputText>
</p:column>
<p:column headerText="Prz" width="20" resizable="true"
filterBy="#{td2.prazo}" filterMatchMode="contains"
filterStyle="max-width: 15px">
<h:outputText value="#{td2.prazo}" style="float:right" />
</p:column>
<p:column headerText="Rst" width="20" resizable="true"
filterBy="#{td2.prazoAtual}" filterMatchMode="contains"
filterStyle="max-width: 15px">
<h:outputText value="#{td2.prazoAtual}" style="float:right" />
</p:column>
<p:column headerText="Descrição da Demanda" width="250"
resizable="true" filterBy="#{td2.descricao}"
filterMatchMode="contains" filterStyle="max-width: 300px">
<h:outputText value="#{td2.descricao}" />
</p:column>
<p:column headerText="Gerência" width="50" resizable="true"
rendered="false" filterBy="#{td2.nomeGerenciaAssessor}"
filterMatchMode="contains" filterStyle="max-width: 40px">
<h:outputText value="#{td2.nomeGerenciaAssessor}" />
</p:column>
<p:column headerText="Divisão" width="200" resizable="true"
rendered="false" filterBy="#{td2.divisaoAssessor}"
filterMatchMode="contains" filterStyle="max-width: 150px">
<h:outputText value="#{td2.divisaoAssessor}" />
</p:column>
<p:column headerText="Gerente de Divisão" width="200"
rendered="false" resizable="true" filterMatchMode="contains"
filterStyle="max-width: 150px">
<h:outputText value="#{td2.nomeGerente}" />
</p:column>
<p:column headerText="Assessor" width="150" resizable="true"
filterBy="#{td2.nomeAssessor}" filterMatchMode="contains"
filterStyle="max-width: 150px">
<h:outputText value="#{td2.nomeAssessor}" />
</p:column>
<p:column headerText="Tipo" width="40" resizable="true"
filterBy="#{td2.tipoDemanda}" filterMatchMode="contains"
filterStyle="max-width: 30px">
<h:outputText value="#{td2.tipoDemanda}">
</h:outputText>
</p:column>
<p:column headerText="Status" width="50" resizable="true"
filterBy="#{td2.status}" filterMatchMode="contains"
filterStyle="max-width: 40px">
<h:outputText value="#{td2.status}">
</h:outputText>
</p:column>
<p:column headerText="Fim" width="30" resizable="true"
filterBy="#{td2.descricaoFinalizado}" filterMatchMode="contains"
filterStyle="max-width: 30px">
<h:outputText value="#{td2.descricaoFinalizado}">
</h:outputText>
</p:column>
</p:dataTable>
<p:dialog id="dlfAlterar" header="Alterar Demanda"
widgetVar="dlgAltDemanda" resizable="false" closeOnEscape="true"
modal="true" height="300" width="800" position="center center">
<div id="alterar"
style="width: 750px; float: center; border: solid 1px #DFDFDF; margin: 10px auto; top: 20px; left: 0px; background: white; padding: 0px;"
class="ui-widget-content ui-corner-bottom ui-corner-top ui-helper-clearfix ui-shadow">
<h:form id="formAlterar" onsubmit=":formConsultar" rendered="true">
<h:panelGrid id="panelPrincipal" columns="1" cellpadding="0"
align="left">
<h:panelGrid id="panelStatusTipoFinalizado" columns="6"
cellpadding="0">
<h:panelGrid columns="1" cellpadding="0">
<p:outputLabel id="label-status" for="status" value="Status:" />
<p:selectOneMenu id="status"
value="#{demanda.demandaSelecionada.idStatus}"
style="width:100px">
<p:message for="status" />
<f:selectItem itemLabel="Sel..." itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{demanda.listaStatus}" var="lista"
itemLabel="#{lista.status}" itemValue="#{lista.id}" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="1" cellpadding="0">
<p:outputLabel id="label-tipo" for="tipo" value="Tipo:" />
<p:selectOneMenu id="tipo"
value="#{demanda.demandaSelecionada.idTipoDemanda}"
style="width:150px">
<f:selectItem itemLabel="Sel..." itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{demanda.listaTipoDemanda}"
var="lista" itemLabel="#{lista.tipoDemanda}"
itemValue="#{lista.id}" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="1" cellpadding="0">
<p:outputLabel id="label-finalizado" for="finalizado"
value="Finalizado:" />
<p:selectOneRadio id="finalizado"
value="#{demanda.demandaSelecionada.finalizado}">
<f:selectItem itemLabel="Sim" itemValue="1" />
<f:selectItem itemLabel="Não" itemValue="0" />
</p:selectOneRadio>
</h:panelGrid>
<h:panelGrid columns="1" cellpadding="0">
<p:outputLabel id="label-inicio" for="inicio"
value="Data Início:" />
<p:calendar id="inicio" effect="slide" pattern="dd/MM/yyyy"
showButtonPanel="false" showOtherMonths="true"
showWeek="false" navigator="true" styleClass="emissao"
locale="pt_BR" size="10"
value="#{demanda.demandaSelecionada.dataInicio}" />
</h:panelGrid>
<h:panelGrid columns="1" cellpadding="0">
<p:outputLabel id="label-vencimento" for="vencimento"
value="Data Vencimento:" />
<p:calendar id="vencimento" effect="slide"
pattern="dd/MM/yyyy" showButtonPanel="false"
showOtherMonths="true" showWeek="false" navigator="true"
styleClass="vencimento" locale="pt_BR" size="10"
value="#{demanda.demandaSelecionada.dataVencimento}" />
</h:panelGrid>
<h:panelGrid columns="1" cellpadding="0">
<p:outputLabel id="label-atendimento" for="atendimento"
value="Data Atendimento:" />
<p:calendar id="atendimento" effect="slide"
pattern="dd/MM/yyyy" showButtonPanel="false"
showOtherMonths="true" showWeek="false" navigator="true"
styleClass="atendimento" locale="pt_BR" size="10"
value="#{demanda.demandaSelecionada.dataAtendimento}" />
</h:panelGrid>
</h:panelGrid>
<h:panelGrid id="panelGerenteAssessor" columns="2"
cellpadding="0">
<h:panelGrid columns="1" cellpadding="0">
<p:outputLabel id="label-gerente" for="gerente"
value="Gerente:" />
<p:selectOneMenu id="gerente"
value="#{demanda.demandaSelecionada.idGerente}"
style="width:300px">
<f:selectItem itemLabel="Sel..." itemValue=""
noSelectionOption="false" />
<f:selectItems var="lista" value="#{demanda.listaGerente}"
itemLabel="#{lista.nome}" itemValue="#{lista.id}" />
<p:ajax listener="#{demanda.funciDivisaoAlt()}"
update=":formConsultar:formAlterar:assessor" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="1" cellpadding="0">
<p:outputLabel id="label-assessor" for="assessor"
value="Assessor:" />
<p:selectOneMenu id="assessor"
value="#{demanda.demandaSelecionada.idAssessor}"
style="width:300px">
<f:selectItem itemLabel="Sel..." itemValue=""
noSelectionOption="false" />
<f:selectItems var="lista"
value="#{demanda.listaFunciDivisaoAlt}"
itemLabel="#{lista.nome}" itemValue="#{lista.id}" />
</p:selectOneMenu>
</h:panelGrid>
</h:panelGrid>
<h:panelGrid id="panelDescricaoGravarCancelar" columns="1"
cellpadding="0">
<p:outputLabel id="label-descricao" for="descricao"
value="Descrição:" />
<p:inputTextarea id="descricao" cols="80" rows="5"
value="#{demanda.demandaSelecionada.descricao}" />
<p:outputLabel />
<h:panelGrid id="panelGravarCancelar" columns="3"
cellpadding="0">
<!-- onclick="redireciona();" -->
<p:commandButton id="botaoGravar" value="Gravar"
action="#{demanda.alterarDemanda()}"
update=":formConsultar, :formConsultar:formAlterar" />
<p:commandButton id="botaoCancelar" value="Cancelar"
update=":formConsultar, :formConsultar:formAlterar"
oncomplete="PF('dlgAltDemanda').hide();" />
</h:panelGrid>
</h:panelGrid>
</h:panelGrid>
</h:form>
</div>
</p:dialog>
</h:form>
</div>
</div>
</h:body>
[/code]
Bean
package br.com.bb.uro.acd.MB;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import br.com.bb.uro.acd.DAO.DemandaDAO;
import br.com.bb.uro.acd.DAO.FuncionarioDAO;
import br.com.bb.uro.acd.DAO.StatusDAO;
import br.com.bb.uro.acd.DAO.TipoDemandaDAO;
import br.com.bb.uro.acd.funcoes.DiasUteis;
import br.com.bb.uro.acd.modelo.Demanda;
import br.com.bb.uro.acd.modelo.DemandaCompleta;
import br.com.bb.uro.acd.modelo.Funcionario;
import br.com.bb.uro.acd.modelo.Status;
import br.com.bb.uro.acd.modelo.TipoDemanda;
@SessionScoped
@ManagedBean(name = "demanda")
public class DemandaMB {
private List<Status> listaStatus;
private List<TipoDemanda> listaTipoDemanda;
private List<Funcionario> listaFunci;
private List<Funcionario> listaFunciDivisao;
private List<Funcionario> listaFunciDivisaoAlt;
private List<Funcionario> listaAssessor;
private List<Funcionario> listaGerente;
private List<Demanda> listaDemanda;
private List<DemandaCompleta> listaDemandaCompleta;
private List<DemandaCompleta> filteredListaDemandaCompleta;
private Demanda demanda;
private DemandaCompleta demandaSelecionada;
private DemandaDAO demandaDAO;
private Integer prazo;
@PostConstruct
public void init() {
demanda = new Demanda();
demandaSelecionada = new DemandaCompleta();
demandaDAO = new DemandaDAO();
}
public void reset() {
demanda = new Demanda();
demandaSelecionada = new DemandaCompleta();
}
// GRAVAR DADOS
public void gravarDemanda() {
DiasUteis du = new DiasUteis();
prazo = du.diasUteis(demanda.getDataInicio(),
demanda.getDataAtendimento());
demanda.setPrazo(prazo);
demandaDAO.adiciona(demanda);
demanda = new Demanda();
}
// Alterar
public void alterarDemanda() {
demanda.setId(demandaSelecionada.getId());
demanda.setDescricao(demandaSelecionada.getDescricao());
demanda.setFinalizado(demandaSelecionada.getFinalizado());
demanda.setIdTipoDemanda(demandaSelecionada.getIdTipoDemanda());
demanda.setIdStatus(demandaSelecionada.getIdStatus());
demanda.setDataInicio(demandaSelecionada.getDataInicio());
demanda.setDataVencimento(demandaSelecionada.getDataVencimento());
demanda.setDataAtendimento(demandaSelecionada.getDataAtendimento());
demanda.setPrazo(demandaSelecionada.getPrazo());
demanda.setIdAssessor(demandaSelecionada.getIdAssessor());
demanda.setIdGerente(demandaSelecionada.getIdGerente());
demandaDAO.altera(demanda);
demanda = new Demanda();
demandaSelecionada = new DemandaCompleta();
}
// Calcula prazo
public int getPrazo(Date dataInicial, Date dataFinal) {
long diferencaMS = dataFinal.getTime() - dataInicial.getTime();
long diferencaSegundos = diferencaMS / 1000;
long diferencaMinutos = diferencaSegundos / 60;
long diferencaHoras = diferencaMinutos / 60;
long diferencaDias = diferencaHoras / 24;
prazo = (int) diferencaDias;
return prazo;
}
// Tabela de demandas completa
public List<DemandaCompleta> getListaDemandaCompleta() {
listaDemandaCompleta = demandaDAO.getListaCompleta();
return listaDemandaCompleta;
}
public List<DemandaCompleta> getFilteredListaDemandaCompleta() {
// filteredListaDemandaCompleta = demandaDAO.getListaCompleta();
return filteredListaDemandaCompleta;
}
public void setFilteredListaDemandaCompleta(
List<DemandaCompleta> filteredListaDemandaCompleta) {
this.filteredListaDemandaCompleta = filteredListaDemandaCompleta;
}
public void setListaDemandaCompleta(
List<DemandaCompleta> listaDemandaCompleta) {
this.listaDemandaCompleta = listaDemandaCompleta;
}
// Tabela de demandas
public List<Demanda> getListaDemanda() {
listaDemanda = demandaDAO.getLista();
return listaDemanda;
}
// Preenche combos
public void funciDivisao() {
this.getListaFunciDivisao();
}
// Preenche combos
public void funciDivisaoAlt() {
this.getListaFunciDivisaoAlt();
}
public List<Funcionario> getListaFunciDivisaoAlt() {
FuncionarioDAO dao = new FuncionarioDAO();
listaFunciDivisaoAlt = dao.getListaFunciDivisao(demandaSelecionada.getIdGerente());
return listaFunciDivisaoAlt;
}
public List<Funcionario> getListaFunciDivisao() {
FuncionarioDAO dao = new FuncionarioDAO();
listaFunciDivisao = dao.getListaFunciDivisao(demanda.getIdGerente());
return listaFunciDivisao;
}
public List<Status> getListaStatus() {
StatusDAO dao = new StatusDAO();
listaStatus = dao.getLista();
return listaStatus;
}
public List<TipoDemanda> getListaTipoDemanda() {
TipoDemandaDAO dao = new TipoDemandaDAO();
listaTipoDemanda = dao.getLista();
return listaTipoDemanda;
}
public List<Funcionario> getListaFunci() {
FuncionarioDAO dao = new FuncionarioDAO();
listaFunci = dao.getLista();
return listaFunci;
}
public List<Funcionario> getListaAssessor() {
FuncionarioDAO dao = new FuncionarioDAO();
listaAssessor = dao.getListaAssessor();
return listaAssessor;
}
public List<Funcionario> getListaGerente() {
FuncionarioDAO dao = new FuncionarioDAO();
listaGerente = dao.getListaGerente();
return listaGerente;
}
public Demanda getDemanda() {
return demanda;
}
public void setDemanda(Demanda demanda) {
this.demanda = demanda;
}
public DemandaCompleta getDemandaSelecionada() {
return demandaSelecionada;
}
public void setDemandaSelecionada(DemandaCompleta demandaSelecionada) {
this.demandaSelecionada = demandaSelecionada;
}
}
Agradeço se puderem me ajudar.