Duvida JSF + PrimesFaces

4 respostas
shenn

Galera, estou fazendo um sistema em jsf, e estou com uma certa dificuldade na hora de listar os dados em uma tabela..

Estou conseguindo lista, mas quando seleciono uma linha e clico para exibir não esta exibindo..

Estou me baseando nesse site aqui: http://www.primefaces.org/showcase-labs/ui/datatableRowSelectionSingle.jsf

segue meu codigo:
package br.com.stefanini.dao;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;

@ManagedBean(name="tableBean") 
public class TableBean {

	private List<Car> carsSmall;
	private Car car;
	
	public TableBean() {
		carsSmall = new ArrayList<Car>();
		populateRandomCars(carsSmall);
	}
	  
    private void populateRandomCars(List<Car> list) {
		for(int i = 0 ; i < 5 ; i++){
			list.add(new Car());
		}
    }
	
	public Car getCar() {
		return car;
	}
	
	public List<Car> getCarsSmall() {
	    return this.carsSmall;
	}
}
Agora meu xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition template="/pages/template/templatedefault.xhtml"
   	  	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">
		
	<ui:define name="conteudo">
		<h:form prependId="false" id="form">
			<div id="listaClienteDIV">
				<p:panel id="painel-listar" header="Lista de Clientes">

				    <p:dataTable id="cars" var="car" value="#{tableBean.carsSmall}" rowKey="#{car.model}"
				                 selection="#{tableBean.car}" selectionMode="single">
				
				        <f:facet name="header">Selecione a linha e clique em "Ver" para detalhes.</f:facet>
				
				        <p:column headerText="Model">
				            #{car.model}
				        </p:column>
				
				        <p:column headerText="Year">
				            #{car.year}
				        </p:column>
				
				        <p:column headerText="Manufacturer" >
				            #{car.manufacturer}
				        </p:column>
				
				        <p:column headerText="Color">
				            #{car.color}
				        </p:column>
				
				        <f:facet name="footer">
				            <p:commandButton id="viewButton" value="Ver" icon="ui-icon-search"
				                    update=":form:display" oncomplete="carDialog.show()"/>
				        </f:facet>
				    </p:dataTable>
					 
				    <p:dialog id="dialog" header="Car Detail" widgetVar="carDialog" resizable="false" 
				    	width="200" showEffect="clip" hideEffect="fold">
				        <h:panelGrid id="display" columns="2" cellpadding="4">
				
				            <h:outputText value="Model:" />
				            <h:outputText value="#{tableBean.car.model}" />
				
				            <h:outputText value="Year:" />
				            <h:outputText value="#{tableBean.car.year}" />
				
				            <h:outputText value="Manufacturer:" />
				            <h:outputText value="#{tableBean.car.manufacturer}" />
				
				            <h:outputText value="Color:" />
				            <h:outputText value="#{tableBean.car.color}" />
				        </h:panelGrid>
				    </p:dialog>
				</p:panel>
			</div>
		</h:form>
	</ui:define>
</ui:composition>

4 Respostas

Hebert_Coelho

Tentou trocar o escopo do seu ManagedBean para view ou session?

Flip_novidade

tenhu um exeplo sussa…
anoite te mando
tou inu pra aula agora

Hebert_Coelho

Exemplo por exemplo tem esse aqui: Aplicação Web Completa Tomcat JSF Primefaces JPA Hibernate.

Tem código fonte e tudo mais. :lol: :lol: :lol:

shenn

Hebert Coelho:

Coloquei o @ViewScoped e o @SessionScoped porem não funcionou…

Estou dando uma olhada no exemplo =D

Criado 5 de dezembro de 2012
Ultima resposta 5 de dez. de 2012
Respostas 4
Participantes 3