Bom dia pessoal.
Iniciei a pouco tempo meus estudos sobre jsf e primefaces e estou com um problema que não estou conseguindo solucionar, editar um objeto em um dialog, basicamente, é carrega-lo no dialog.
Estou usando um data table com selection single mode. O objeto e clicar em uma das linhas (objeto) e, em seguida, clicar no botão editar e, então, o dialog carregaria uma janela para a edição das informações deste objeto, acontece que o dialog não carrega este objeto.
Montei um pequeno exemplo para mostrar meu problema mais facilmente,
Abaixo, minha class teste.xhtml
<?xml version="1.0" encoding="UTF-8" ?>
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/_template.xhtml">
<ui:define name="corpo">
<h:form id="form">
<p:tabView>
<p:tab title="teste">
<fieldset>
<legend>Tabela Teste</legend>
<p:dataTable id="teste" var="teste" value="#{testeBean.testes}" selectionMode="single"
selection="#{testeBean.teste}" rowKey="#{teste.id}" >
<p:column id="descricao" filterBy="#{teste.descricao}" >
<h:outputText value="#{teste.descricao}" />
</p:column>
</p:dataTable>
<p:commandButton id="novo" value="Novo" onclick="novoDialogo.show()" type="button" />
<p:commandButton id="editar" value="Editar" onclick="novoDialogoEdit.show()" type="button" >
<f:ajax render="modalTesteEditar" execute="@form" />
</p:commandButton>
<p:dialog id="modalTesteNovo" header="Teste Modal" widgetVar="novoDialogo" modal="true" dynamic="true" >
<h:outputText value="Descrição: " />
<p:inputText value="#{testeBean.teste.descricao}" />
<p:commandButton value="Salvar" action="#{testeBean.grava}" oncomplete="novoDialogo.hide()" onclick="teste" >
<f:ajax execute="@this" render="@form" />
</p:commandButton>
</p:dialog>
<p:dialog id="modalTesteEditar" header="Teste Modal Edit" widgetVar="novoDialogoEdit" modal="true" dynamic="true" >
<h:outputText value="#{testeSelecionado.descricao}" />
</p:dialog>
</fieldset>
</p:tab>
</p:tabView>
</h:form>
</ui:define>
</ui:composition>
</html>
Aqui esta meu ManagedBean:
package br.com.enterprisestoq.bean;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import br.com.enterprisestoq.dao.DAO;
import br.com.enterprisestoq.modelos.Teste;
@ManagedBean
@ViewScoped
public class TesteBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Teste teste = new Teste();
private Teste testeSelecionado;
private List<Teste> testes;
public String grava(){
DAO<Teste> dao = new DAO<Teste>(Teste.class);
dao.adiciona(teste);
this.teste = new Teste();
return "teste";
}
public Teste getTeste() {
return teste;
}
public void setTeste(Teste teste) {
this.teste = teste;
}
public List<Teste> getTestes() {
DAO<Teste> dao = new DAO<Teste>(Teste.class);
this.testes = dao.listaTodos();
return this.testes;
}
public void setTestes(List<Teste> testes) {
this.testes = testes;
}
public Teste getTesteSelecionado() {
return testeSelecionado;
}
public void setTesteSelecionado(Teste testeSelecionado) {
this.testeSelecionado = testeSelecionado;
}
}
O que estou fazendo de errado? Ja tentei seguir o exemplo dos cases do site do primefaces, porém o resultado é o mesmo.
Muito obrigado.