Olá pessoal,estou com uma dúvida terrível que a uma semana vem me atrapalhando.
Acontece do seguinte, estou tentando fazer uma pesquisa usando um dataTable dento de um Dialog.
Acontece que a pesquisa é feita, o atributo que uso como lista recebe o resultado da pesquisa, o dataTable se atualiza com os valores encontrados, mas na hora em que seleciono uma linha, a seleção faz refência a outro objeto.
Se álguem souber uma solução fico grato.
página .xhmtl
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
template="./templates/principal.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:define name="content">
<h:form>
<h:outputText value="nome" />
<h:inputText value="#{teste.nome}" />
<p:commandButton ajax="false" value="Procurar" actionListener="#{teste.pesquisa}" update="table" />
<p:dataTable value="#{teste.alunos}" var="a" id="table"
selection="#{teste.aluno}" selectionMode="single" update="nome" >
<p:column>
<f:facet name="header">
<h:outputText value="Nome" />
</f:facet>
<h:outputText value="#{a.nome}" />
</p:column>
</p:dataTable>
<h:outputText value="#{teste.aluno.nome}" id="nome" />
</h:form>
</ui:define>
</ui:composition>
ManagedBean
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.projeto.controle;
import br.com.projeto.dao.DaoAluno;
import br.com.projeto.modelo.Aluno;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ActionEvent;
/**
*
* @author ALUNO
*/
@ManagedBean
@RequestScoped
public class Teste {
private String nome;
private List<Aluno> alunos;
private Aluno aluno;
private DaoAluno daoAluno = new DaoAluno();
public Teste() {
alunos = (List<Aluno>) daoAluno.list();
}
public void pesquisa(ActionEvent E){
alunos = (List<Aluno>) daoAluno.pegarTodosLike("nome", nome);
}
public Aluno getAluno() {
return aluno;
}
public void setAluno(Aluno aluno) {
this.aluno = aluno;
}
public List<Aluno> getAlunos() {
return alunos;
}
public void setAlunos(List<Aluno> alunos) {
this.alunos = alunos;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}