JSF - Recuperar Linha

Galera, estou com uma duvida…

Estou exibindo em uma tabela os dados do meu cliente (que por enquanto só tem nome), queria selecionar essa linha por um botão e colocar aqueles dados em um modal…

Porem não estou conseguindo trazer no modal os dados… ja tentei um monte de coisas e nada…

Alguem sabe o porque?

Segue meu fonte:

// MEU BEAN
public class TesteBean {

	private String nome;

	public String getNome() {return nome;}
	public void setNome(String nome) {this.nome = nome;}
}

// CLASSE QUE EXIBE A LISTA E RECUPERA A SELECIONADA
@ManagedBean(name="cadClientes")
public class TesteMB {

	private TesteBean bean = new TesteBean();
	private TesteBean linhaSelecionada= new TesteBean();
	private List<TesteBean> lista = new ArrayList<TesteBean>();

	// GET E SET
	public TesteBean getBean() {return bean;}
	public TesteBean getLinhaSelecionada() {return linhaSelecionada;}
	public List<TesteBean> getLista() {return lista;}
	public void setLinhaSelecionada(TesteBean linhaSelecionada) {this.linhaSelecionada = linhaSelecionada;}
	public void setLista(List<TesteBean> lista) {this.lista = lista;}
	public void setBean(TesteBean bean) {this.bean = bean;}
	
	public String listar(){
		bean = new TesteBean();
		bean.setNome("Thales");
		lista.add(bean);
		bean = new TesteBean();
		bean.setNome("Thatiana");
		lista.add(bean);
		
		return "listar";
	}
}

// MEU XHTML QUE TEM O BOTAO PARA CHAMAR A CLASSE E LISTAR
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

	<h:head><title>Titulo</title></h:head>
	<h:body>
		<h:form prependId="false">
			<p:commandButton ajax="false" value="Listar" action="#{cadClientes.listar}"></p:commandButton>
		</h:form>
	</h:body>
</html>

// MINHA LISTA
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

	<h:head><title>Titulo</title></h:head>
	<h:body>
		<h:form prependId="false" id="form">
			<p:panel header="Lista de Clientes">
			    <p:dataTable var="bean" value="#{cadClientes.lista}">
			    
			   		 <p:column headerText="Nome">
			   		 	  <h:outputText value="#{bean.nome}"/>
			   		 </p:column>
			   		
			   		 <p:column headerText="Vizualizar">
			   		 	  <p:commandButton update=":form:display" icon="ui-icon-search" value="Ver" oncomplete="clienteDisplay.show()">
                               <f:setPropertyActionListener target="#{cadClientes.linhaSelecionada}" value="#{bean}"/>
                         </p:commandButton>  
			   		 </p:column>
			    </p:dataTable>
			</p:panel>
		
			<p:dialog widgetVar="clienteDisplay" id="modal-cliente" modal="true" resizable="false">
				<h:panelGrid id="display"> 
					<h:outputText value="#{cadClientes.linhaSelecionada.nome}"/>
				</h:panelGrid>
			</p:dialog>
		</h:form>
	</h:body>
</html>

Alguem sabe o porque?!

vllw =D

Você tem que dar um update no form.

Eu estou dando um update no form aqui não?!


<p:commandButton update=":form:display" icon="ui-icon-search" value="Ver" oncomplete="clienteDisplay.show()">

pelo que vi vc nao ta atualizando a modal, tenta assim:

<p:commandButton update="modal-cliente" icon="ui-icon-search" value="Ver" oncomplete="clienteDisplay.show()">  
        <f:setPropertyActionListener target="#{cadClientes.linhaSelecionada}" value="#{bean}"/>  
</p:commandButton>  

da uma olhada no escopo do bean tbm, deixe em @ViewScoped

Polverini

Tentei fazer isso que você falou, alterei o update e não funciou e quando eu coloquei o scope como @ViewScoped a lista nem carregou…

Coloca o dialog em um form separado, e quando clicar no botão para chama-lo da o update no form do dialog.

Funcionou =D

Valeu carinha, estava com essa duvida há alguns dias já!!

brigadão…

segue como ficou para quem tiver duvidas no futuro:

<!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:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

	<h:head><title>Titulo</title></h:head>
	<h:body>
		<h:form prependId="false" id="form">
			<p:panel header="Lista de Clientes">
			    <p:dataTable var="bean" value="#{cadClientes.lista}">
			    
			   		 <p:column headerText="Nome">
			   		 	  <h:outputText value="#{bean.nome}"/>
			   		 </p:column>
			   		
			   		 <p:column headerText="Vizualizar">
			   		 	  <p:commandButton update="form2" icon="ui-icon-search" value="Ver" oncomplete="clienteDisplay.show()">
                               <f:setPropertyActionListener target="#{cadClientes.linhaSelecionada}" value="#{bean}"/>
                         </p:commandButton>  
			   		 </p:column>
			    </p:dataTable>
			</p:panel>
		</h:form>
		<h:form id="form2">
			<p:dialog widgetVar="clienteDisplay" id="modal-cliente" modal="true" resizable="false">
				<h:panelGrid id="display"> 
					<h:outputText value="#{cadClientes.linhaSelecionada.nome}"/>
				</h:panelGrid>
			</p:dialog>
		</h:form>
	</h:body>
</html>

Qual tipo de escopo é seu managedBean

exemplo

@ManagedBean(name=“cadClientes”)
@ViewScoped -----------------------> falta colocar o escopo dele
public class TesteMB {
.
.
.
}