andre.froes 15 de mai. de 2012
Ao importar o primefaces 3.2 você está utilizando qual importação da lib?
Novo: xmlns:p=“http://primefaces.org/ui ”
ou
Antigo: xmlns:p=“http://primefaces.prime.com.tr/ui ”
não lembro em qual versão que mudou o link do core
victorgilc 15 de mai. de 2012
Uso a nova, tanto com o 3 quanto com o 3.2
PS: Uso o GlassFish 3.1
andre.froes 15 de mai. de 2012
coloca teu código aí, o cabeçalho e parte do body onde está o growl e o datatable
victorgilc 15 de mai. de 2012
O cabeçalho:
<ui:composition template="templates/templategerenciador.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ccomp="http://java.sun.com/jsf/composite/ccomp"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ezcomp="http://java.sun.com/jsf/composite/ezcomp"
xmlns:c="http://java.sun.com/jsp/jstl/core">
Minha tabela:
< h : form id = "formPrincipal" prependId = "false" >
< p : dataTable widgetVar = "tableCadastroEventos"
emptyMessage = "#{propriedades.GERAL_NENHUM_REGISTRO_ENCONTRADO}"
value = "#{eventosController.eventosLista}"
var = "item"
rows = "10" selectionMode = "single"
selection = "#{eventosController.evento}"
rowKey = "#{item.id}"
paginator = "true" paginatorTemplate = "#{componentes_pf.PAGINATOR_TEMPLATE}"
currentPageReportTemplate = "#{componentes_pf.CURRENT_PAGE_REPORT_TEMPLATE}"
paginatorPosition = "top"
rowsPerPageTemplate = "5,10,15,20,25,30"
style = "margin-top: 5px;" >
< p : column headerText = "#{propriedades.NOTICIA_ID}" style = "text-align: center; width: 40px;" >
< h : outputText value = "#{item.id}" />
</ p : column >
< p : column headerText = "#{propriedades.EVENTOS_NOME}" style = "text-align: center; width: 40px;" >
< h : outputText value = "#{item.nomeEvento}" />
</ p : column >
< p : column headerText = "#{propriedades.EVENTOS_DATA_INICIO}" style = "text-align: center; width: 40px;" >
< h : outputText value = "#{item.dataInicio}" >
< f : convertDateTime pattern = "dd/MM/yyyy" />
</ h : outputText >
</ p : column >
< p : column headerText = "#{propriedades.EVENTOS_DATA_FIM}" style = "text-align: center; width: 40px;" >
< h : outputText value = "#{evento.dataFim}" >
< f : convertDateTime pattern = "dd/MM/yyyy" />
</ h : outputText >
</ p : column >
</ p : dataTable >
</ h : form >
E o meu growl, que está no meu template
<h:form prependId= "false" >
<p:growl id= "messages" widgetVar= "messages" showDetail= "true" life= "5000" sticky= "false" autoUpdate= "true" />
</h:form>
cbs_sp 15 de mai. de 2012
Caro amigo,
Deve ser algum problema na library do PF, tenta remover e adicionar novamente, e dá um clean & build. (Verifique tb o jar que vc baixou).
Testei seu exemplo aqui com PF 3.2, e GF 3.1.1., e funcionou perfeitamente.
Vc pode baixar o exemplo aqui, funcionando:
codepianist.com/2012/05/exemplo-de-um-primefaces-3-2-datatable-com-selecao/
Um grande abraço e sucesso!
Polverini 15 de mai. de 2012
pelo que eu vi no prime 3.2 vc tem que implementar a classe SelectableDataModeler para efetuar a seleção, eu uso assim:
public class SetorSelectDataModel extends ListDataModel < Setor > implements SelectableDataModel < Setor > {
public SetorSelectDataModel () {
}
public SetorSelectDataModel ( List < Setor > data ) {
super ( data );
}
@ Override
public Object getRowKey ( Setor setor ) {
return setor . getId ();
}
@ Override
public Setor getRowData ( String rowKey ) {
List < Setor > setores = ( List < Setor > ) getWrappedData ();
for ( Setor s : setores ) {
if ( s . getId () == Long . parseLong ( rowKey )) {
return s ;
}
}
return null ;
}
}
veja mais aqui:
http://www.primefaces.org/showcase-labs/ui/datatableRowSelectionRadioCheckbox.jsf
cbs_sp 15 de mai. de 2012
Este exemplo (link que vc postou) tá funcionando com a nova versão PrimeFaces-3.3-SNAPSHOT, que ainda não tá estável.
Até onde pude constatar, para um seleção simples não há necessidade de implementar esta interface.
O exemplo que fiz selecionou a linha do datatable sem problemas.
Este novo exemplo, com classe SetorSelectDataModel, funcionou com o jar do 3.2?
[]s
Polverini 15 de mai. de 2012
estou sando o primefaces 3.2 mesmo e da um erro se eu nao usar juntamente com o seletabledatamodeler
cbs_sp 15 de mai. de 2012
Acho que o importante é que funcionou, no mínimo o Victor já tem 2 versões funcionando (com e sem SelectableDataModel).
Se quiser pode baixar a versão que subi no site e testar (tá funcionando sem o SelectableDataModel).
codepianist.com/2012/05/exemplo-de-um-primefaces-3-2-datatable-com-selecao/
.xhtml:
& lt ; ? xml version = '1.0' encoding = 'UTF-8' ? & gt ;
& lt ; ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" & gt ;
& lt ; html xmlns = "http://www.w3.org/1999/xhtml"
xmlns : ui = "http://java.sun.com/jsf/facelets"
xmlns : p = "http://primefaces.org/ui"
xmlns : f = "http://java.sun.com/jsf/core"
xmlns : h = "http://java.sun.com/jsf/html"
xmlns : c = "http://java.sun.com/jsp/jstl/core" & gt ;
& lt ; h : head & gt ;
& lt ; title & gt ; Datatable example & lt ; / title & gt ;
& lt ; / h : head & gt ;
& lt ; h : body & gt ;
& lt ; h : form id = "formMessages" & gt ;
& lt ; p : growl id = "messages" widgetVar = "messages" showDetail = "true" life = "5000" sticky = "false" autoUpdate = "true" /& gt ;
& lt ; / h : form & gt ;
& lt ; h : form id = "formPrincipal" & gt ;
& lt ; p : dataTable value = "#{datatableBean.products}" var = "item"
selection = "#{datatableBean.selected}" selectionMode = "single"
rowKey = "#{item.id}"
emptyMessage = "Nenhum produto encontrado!"
style = "margin-top: 5px;" & gt ;
& lt ; f : facet name = "header" & gt ;
Clique no item para selecion & aacute ; - lo
& lt ; / f : facet & gt ;
& lt ; p : column headerText = "Código" style = "text-align: center; width: 40px;" & gt ;
& lt ; h : outputText value = "#{item.id}" /& gt ;
& lt ; / p : column & gt ;
& lt ; p : column headerText = "Nome" style = "text-align: center; width: 40px;" & gt ;
& lt ; h : outputText value = "#{item.name}" /& gt ;
& lt ; / p : column & gt ;
& lt ; p : column headerText = "Descrição" style = "text-align: center; width: 40px;" & gt ;
& lt ; h : outputText value = "#{item.detail}" /& gt ;
& lt ; / p : column & gt ;
& lt ; p : column headerText = "Preço" style = "text-align: center; width: 40px;" & gt ;
& lt ; h : outputText value = "#{item.price}" /& gt ;
& lt ; / p : column & gt ;
& lt ; f : facet name = "footer" & gt ;
& lt ; p : commandButton id = "viewButton" value = "Mostrar produto" icon = "ui-icon-search"
update = ":formPrincipal:display" oncomplete = "productDialog.show()" /& gt ;
& lt ; / f : facet & gt ;
& lt ; / p : dataTable & gt ;
& lt ; p : dialog id = "dialog" header = "Produto selecionado" widgetVar = "productDialog" resizable = "false"
width = "400" showEffect = "clip" hideEffect = "fold" & gt ;
& lt ; h : panelGrid id = "display" columns = "2" cellpadding = "4" & gt ;
& lt ; h : outputText value = "Nome:" /& gt ;
& lt ; h : outputText value = "#{datatableBean.selected.name}" /& gt ;
& lt ; h : outputText value = "Descrição:" /& gt ;
& lt ; h : outputText value = "#{datatableBean.selected.detail}" /& gt ;
& lt ; h : outputText value = "Preço:" /& gt ;
& lt ; h : outputText value = "#{datatableBean.selected.price}" /& gt ;
& lt ; / h : panelGrid & gt ;
& lt ; / p : dialog & gt ;
& lt ; / h : form & gt ;
& lt ; / h : body & gt ;
& lt ; / html & gt ;
.java
/**
*
* @author Cesar Barbosa
* @version 0.1
*/
@Named
@RequestScoped
public class DatatableBean {
@PostConstruct
public void init (){
products = new ArrayList & lt ; Product & gt ;();
products . add ( new Product ( 1 , "Sabonete Cheirinho" , "chiii" , 5.88 ));
products . add ( new Product ( 2 , "Macarrão de Yakisoba 500g" , "hummmm" , 4.32 ));
products . add ( new Product ( 3 , "Refrigerante Tubaina 2L" , "ehhhh" , 1.52 ));
products . add ( new Product ( 4 , "Travesseiro de pedra" , "Ops!" , 13.78 ));
}
private List & lt ; Product & gt ; products ;
private Product selected ;
public List & lt ; Product & gt ; getProducts () {
return products ;
}
public void setProducts ( List & lt ; Product & gt ; products ) {
this . products = products ;
}
public Product getSelected () {
return selected ;
}
public void setSelected ( Product selected ) {
this . selected = selected ;
FacesMessage msg = new FacesMessage ( "Produto selecionado!" , "Produto: " + selected . getName ());
msg . setSeverity ( FacesMessage . SEVERITY_INFO );
FacesContext . getCurrentInstance (). addMessage ( null , msg );
}
}
Um grande abraço,
victorgilc 15 de mai. de 2012
Olá Cesar e Polverini
Obrigado pelas respostas, as duas versões rodam perfeitamente ^^.
cbs_sp 15 de mai. de 2012
Não há de que.
Quando tiver um tempo marca como [Resolvido].
Um grande abraço e sucesso!