Richfaces 4 - datatable - Fazer os dados de um list aparecer nas linhas e colunas

9 respostas
Z

Galera, bom dia

Estou estudando JSF 2 e RIchfaces 4 e estou tentando usar um datatable do richfaces, criei uma lista fake no managed bean, porém ao carregar a página nada acontece, a lista nem é chamada, e mesmo que eu coloque um nome qualquer para o bean, nada acontece. Por que será? o que eu faço de errado?

Lista principal:
<ui:composition template="/templates/templategeral.xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">
	<ui:define name="crudArea">
		<ui:include src="/components/listcomponent.xhtml" />
	</ui:define>
</ui:composition>
Componente usado na lista
<ui:component xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:f="http://java.sun.com/jsf/core">

	<rich:panel>
		<f:facet name="header">
			<h:outputText value="Filtro" />
		</f:facet>
		<h:outputText value="Período" />
		<rich:calendar value="" datePattern="dd/M/yy HH:mm:ss" />
		<rich:calendar value="" datePattern="dd/M/yy HH:mm:ss" />
		<h:selectBooleanCheckbox value="" />
		<h:outputText value="Somente ativos" />
		<h:button value="Atualizar" />

	</rich:panel>
	<h:panelGroup id="groupLink">
		<h:commandLink action="a" value="Novo" />
		<h:commandLink action="a" value="Alterar" />
		<h:commandLink action="a" value="Excluir" />
	</h:panelGroup>
	<h:panelGroup id="list">
		<rich:dataTable cellpadding="0" cellspacing="0" width="700"
			border="0" var="pit" value="#{pitMB.pitsList}">
			<rich:column>
				<h:outputText value="#{pit.dataInicioPit}" />
			</rich:column>
			<rich:column>
				<h:outputText value="#{pit.numero}" />
			</rich:column>
			<rich:column>
				<h:outputText value="#{pit.descricaoPit}" />
			</rich:column>
		</rich:dataTable>

	</h:panelGroup>
</ui:component>

Managed bean que deveria ser chamada pela página, principalmente o método getPitsList

@ManagedBean(name="pitMB")
public class PitMB {

	private List<Pit>  pitsEmAberto;
	
	public List<Pit> getPitsList(){
		pitsEmAberto = new ArrayList<Pit>();
		Pit pit = Pit.createPit(1l, new Cliente(), "Teste 1", false, new Date(), null, "teste");
		Pit pit2 = Pit.createPit(2l, new Cliente(), "Teste 2", false, new Date(), null, "teste");
		Pit pit3 = Pit.createPit(3l, new Cliente(), "Teste 3", false, new Date(), null, "teste");
		Pit pit4 = Pit.createPit(4l, new Cliente(), "Teste 4", false, new Date(), null, "teste");
		
		
		pitsEmAberto.add(pit);
		pitsEmAberto.add(pit2);
		pitsEmAberto.add(pit3);
		pitsEmAberto.add(pit4);
		return pitsEmAberto;
	}
}

obrigado

9 Respostas

Hebert_Coelho

Seu código está cercado por <h:head> e <h:body>?
E por um <h:form> também?

Z
jakefrog:
Seu código está cercado por e ? E por um também?

essa página List herda de uma outra página chamada templategeral que por sua vez herda de template. Eu realmente não tinha colocado a tag form, no template abaixo está o código novo que coloquei (não tinha form antes), porém não mudou muito, acho que to colocando algo fora de ordem.

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

<h:head>
	<div id="head">
		<ui:insert name="head">

		</ui:insert>
	</div>
</h:head>

<h:body>
	<h:form id="formgeral">
		<div id="body">
			<ui:insert name="body" />
		</div>
	</h:form>
</h:body>

</html>

e o template geral

<?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:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:rich="http://richfaces.org/rich">
<h:body>
	<ui:composition template="template.xhtml">
		<h:outputText value="teste aqui" />
		<ui:define name="body">
			<h:form id="formGeral">
				<div id="headerDiv">
					<ui:insert name="header">
						<h:panelGroup id="header">
							<rich:panel>
								<h:outputText value="Testando o Cabeçalho" />
							</rich:panel>
						</h:panelGroup>
					</ui:insert>
				</div>
				<h:panelGrid columns="2" id="princTela">
					<ui:insert name="menuArea">
						<ui:include src="menu.xhtml" />
					</ui:insert>

					<ui:insert name="crudArea">
					    <h:outputText value="adicione uma área de crud válida" />
					</ui:insert>

				</h:panelGrid>
				<ui:insert name="footer">
					<div id="footerDiv">
						<h:panelGroup id="footer">
							<rich:panel>
								<h:outputText value="Testando o  rodape 2" />
							</rich:panel>
						</h:panelGroup>
					</div>
				</ui:insert>
			</h:form>
		</ui:define>
	</ui:composition>
</h:body>
</html>
Z

na verdade, eu to meio com sono já, eu tinha colocado sim o <h:form> no templategeral, então eu tinha colocado as 3 tags que vc tinha perguntado, só não sei se nas posições certas

Hebert_Coelho

Tem dois <h:body> no mais alto nível possível.

Para quem herdar, ele body já vai estar definido.

Depois disso, não está dando erro ou nenhum comportamento diferente?

No método getPitsList() coloca um System.out.println(“Fui chamado”); para você saber se foi chamado ou não.

E se tiver pregado de sono, descanse pq vai ser melhor tu levantar e ta na moral amanhã do que ficar batalhando aí.

Z

blz, vou fazer isso kkk

Amanhã eu digo se consegui, obrigado pela ajuda

Z
jakefrog:
Tem dois no mais alto nível possível.

Para quem herdar, ele body já vai estar definido.

Depois disso, não está dando erro ou nenhum comportamento diferente?

No método getPitsList() coloca um System.out.println("Fui chamado"); para você saber se foi chamado ou não.

então, jakefrog o compotamento estranho é não chamar o método mesmo, nem mesmo o construtor do MB é chamado. O fonte gerado tem a table em html criado pelo componente richtable, eu olhei isso pq poderia ser que o não tivesse entendendo os templates do facelets.

<?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"><head><link type="text/css" rel="stylesheet" href="/rd/rfRes/skinning.ecss.xhtml?db=eAG78eJxOQAIWQMb" /><link type="text/css" rel="stylesheet" href="/rd/rfRes/panel.ecss.xhtml?db=eAG78eJxOQAIWQMb&amp;ln=org.richfaces" /><script type="text/javascript" src="/rd/javax.faces.resource/jsf.js.xhtml?ln=javax.faces"></script><script type="text/javascript" src="/rd/javax.faces.resource/jquery.js.xhtml"></script><script type="text/javascript" src="/rd/javax.faces.resource/richfaces.js.xhtml"></script><script type="text/javascript" src="/rd/javax.faces.resource/richfaces-queue.js.xhtml"></script><script type="text/javascript" src="/rd/javax.faces.resource/richfaces-event.js.xhtml"></script><script type="text/javascript" src="/rd/javax.faces.resource/richfaces-base-component.js.xhtml"></script><script type="text/javascript" src="/rd/javax.faces.resource/panelMenu.js.xhtml?ln=org.richfaces"></script><script type="text/javascript" src="/rd/javax.faces.resource/panelMenuItem.js.xhtml?ln=org.richfaces"></script><script type="text/javascript" src="/rd/javax.faces.resource/panelMenuGroup.js.xhtml?ln=org.richfaces"></script><link type="text/css" rel="stylesheet" href="/rd/rfRes/icons.ecss.xhtml?db=eAG78eJxOQAIWQMb&amp;ln=org.richfaces" /><link type="text/css" rel="stylesheet" href="/rd/rfRes/panelMenu.ecss.xhtml?db=eAG78eJxOQAIWQMb&amp;ln=org.richfaces" /><script type="text/javascript" src="/rd/javax.faces.resource/jquery.position.js.xhtml"></script><script type="text/javascript" src="/rd/javax.faces.resource/json-dom.js.xhtml?ln=org.richfaces"></script><script type="text/javascript" src="/rd/javax.faces.resource/jquery.effects.core.js.xhtml?ln=org.richfaces"></script><script type="text/javascript" src="/rd/javax.faces.resource/jquery.effects.highlight.js.xhtml?ln=org.richfaces"></script><script type="text/javascript" src="/rd/javax.faces.resource/JQuerySpinBtn.js.xhtml?ln=org.richfaces"></script><script type="text/javascript" src="/rd/javax.faces.resource/calendar-utils.js.xhtml?ln=org.richfaces"></script><script type="text/javascript" src="/rd/javax.faces.resource/calendar.js.xhtml?ln=org.richfaces"></script><link type="text/css" rel="stylesheet" href="/rd/rfRes/calendar.ecss.xhtml?db=eAG78eJxOQAIWQMb&amp;ln=org.richfaces" /><script type="text/javascript" src="/rd/javax.faces.resource/datatable.js.xhtml?ln=org.richfaces"></script><link type="text/css" rel="stylesheet" href="/rd/rfRes/datatable.ecss.xhtml?db=eAG78eJxOQAIWQMb&amp;ln=org.richfaces" />

	<div id="head">
	</div></head><body>

			<div id="headerDiv"><span id="header"><div class="rf-p " id="j_idt8"><div class="rf-p-b " id="j_idt8_body">Testando o Cabeçalho</div></div></span>
			</div><table id="princTela">
<tbody>
<tr>
<td><div id="j_idt12" class="rf-pm" style="width:200px"><input id="j_idt12-value" name="j_idt12-value" type="hidden" /><script type="text/javascript">new RichFaces.ui.PanelMenu("j_idt12",{"bubbleSelection":true,"ajax":{"incId":"1"} ,"expandSingle":true,"disabled":false} )</script><div id="j_idt13" class="rf-pm-top-gr"><input id="j_idt13:expanded" name="j_idt13:expanded" type="hidden" value="false" /><div id="j_idt13:hdr" class="rf-pm-top-gr-hdr rf-pm-hdr-colps"><table class="rf-pm-top-gr-gr"><tbody><tr><td class="rf-pm-top-gr-ico"><div class="rf-pm-ico-colps rf-ico-transparent-hdr"></div><div class="rf-pm-ico-exp rf-ico-transparent-hdr"></div></td><td class="rf-pm-top-gr-lbl">Group 1</td><td class="rf-pm-top-gr-exp-ico"><div class="rf-pm-ico-colps rf-ico-chevron-down-hdr"></div><div class="rf-pm-ico-exp rf-ico-chevron-up-hdr"></div></td></tr></tbody></table></div><div id="j_idt13:cnt" class="rf-pm-top-gr-cnt rf-pm-colps"><script type="text/javascript">new RichFaces.ui.PanelMenuGroup("j_idt13",{"collapseEvent":"click","unselectable":false,"selectable":false,"name":"j_idt13","ajax":{"incId":"1"} ,"stylePrefix":"rf\u002Dpm\u002Dtop\u002Dgr","expanded":false,"expandEvent":"click","disabled":false,"mode":"ajax"} )</script></div></div><div id="j_idt17" class="rf-pm-top-gr"><input id="j_idt17:expanded" name="j_idt17:expanded" type="hidden" value="false" /><div id="j_idt17:hdr" class="rf-pm-top-gr-hdr rf-pm-hdr-colps"><table class="rf-pm-top-gr-gr"><tbody><tr><td class="rf-pm-top-gr-ico"><div class="rf-pm-ico-colps rf-ico-transparent-hdr"></div><div class="rf-pm-ico-exp rf-ico-transparent-hdr"></div></td><td class="rf-pm-top-gr-lbl">Group 2</td><td class="rf-pm-top-gr-exp-ico"><div class="rf-pm-ico-colps rf-ico-chevron-down-hdr"></div><div class="rf-pm-ico-exp rf-ico-chevron-up-hdr"></div></td></tr></tbody></table></div><div id="j_idt17:cnt" class="rf-pm-top-gr-cnt rf-pm-colps"><script type="text/javascript">new RichFaces.ui.PanelMenuGroup("j_idt17",{"collapseEvent":"click","unselectable":false,"selectable":false,"name":"j_idt17","ajax":{"incId":"1"} ,"stylePrefix":"rf\u002Dpm\u002Dtop\u002Dgr","expanded":false,"expandEvent":"click","disabled":false,"mode":"ajax"} )</script></div></div><div id="j_idt26" class="rf-pm-top-gr"><input id="j_idt26:expanded" name="j_idt26:expanded" type="hidden" value="false" /><div id="j_idt26:hdr" class="rf-pm-top-gr-hdr rf-pm-hdr-colps"><table class="rf-pm-top-gr-gr"><tbody><tr><td class="rf-pm-top-gr-ico"><div class="rf-pm-ico-colps rf-ico-transparent-hdr"></div><div class="rf-pm-ico-exp rf-ico-transparent-hdr"></div></td><td class="rf-pm-top-gr-lbl">Group 3</td><td class="rf-pm-top-gr-exp-ico"><div class="rf-pm-ico-colps rf-ico-chevron-down-hdr"></div><div class="rf-pm-ico-exp rf-ico-chevron-up-hdr"></div></td></tr></tbody></table></div><div id="j_idt26:cnt" class="rf-pm-top-gr-cnt rf-pm-colps"><script type="text/javascript">new RichFaces.ui.PanelMenuGroup("j_idt26",{"collapseEvent":"click","unselectable":false,"selectable":false,"name":"j_idt26","ajax":{"incId":"1"} ,"stylePrefix":"rf\u002Dpm\u002Dtop\u002Dgr","expanded":false,"expandEvent":"click","disabled":false,"mode":"ajax"} )</script></div></div></div></td>

<td><div class="rf-p " id="j_idt31"><div class="rf-p-hdr " id="j_idt31_header">Filtro</div><div class="rf-p-b " id="j_idt31_body">Período<span id="j_idt34"><span id="j_idt34Popup" style="white-space: nowrap;"><input class="rf-cal-inp " id="j_idt34InputDate" name="j_idt34InputDate" readonly="readonly" style="vertical-align: middle; " type="text" /><img alt="" class="rf-cal-btn " id="j_idt34PopupButton" src="/rd/rfRes/calendarIcon.png.xhtml?v=4.0.0.Final&amp;db=eAH7P4GB4f!!KZwAFBoEKw__&amp;ln=org.richfaces.images" style="vertical-align: middle" /><input autocomplete="off" id="j_idt34InputCurrentDate" name="j_idt34InputCurrentDate" style="display:none" type="hidden" value="12/2011" /></span><span id="j_idt34Content" style="display: none;"></span><span id="j_idt34Script" style="display: none;"><script type="text/javascript">RichFaces.ui.Calendar.addLocale("pt_BR", 
					{"monthLabels":["Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"] ,"minDaysInFirstWeek":1,"monthLabelsShort":["Jan","Fev","Mar","Abr","Mai","Jun","Jul","Ago","Set","Out","Nov","Dez"] ,"firstWeekDay":1,"weekDayLabels":["Domingo","Segunda\u002Dfeira","Terça\u002Dfeira","Quarta\u002Dfeira","Quinta\u002Dfeira","Sexta\u002Dfeira","Sábado"] ,"weekDayLabelsShort":["Dom","Seg","Ter","Qua","Qui","Sex","Sáb"] } );
				new RichFaces.ui.Calendar("j_idt34", "pt_BR",
					{"datePattern":"dd\/M\/yy HH:mm:ss","currentDate":new Date(2011,11,20),"style":"z\u002Dindex: 3"} ).load();</script></span></span><span id="j_idt35"><span id="j_idt35Popup" style="white-space: nowrap;"><input class="rf-cal-inp " id="j_idt35InputDate" name="j_idt35InputDate" readonly="readonly" style="vertical-align: middle; " type="text" /><img alt="" class="rf-cal-btn " id="j_idt35PopupButton" src="/rd/rfRes/calendarIcon.png.xhtml?v=4.0.0.Final&amp;db=eAH7P4GB4f!!KZwAFBoEKw__&amp;ln=org.richfaces.images" style="vertical-align: middle" /><input autocomplete="off" id="j_idt35InputCurrentDate" name="j_idt35InputCurrentDate" style="display:none" type="hidden" value="12/2011" /></span><span id="j_idt35Content" style="display: none;"></span><span id="j_idt35Script" style="display: none;"><script type="text/javascript">RichFaces.ui.Calendar.addLocale("pt_BR", 
					{"monthLabels":["Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"] ,"minDaysInFirstWeek":1,"monthLabelsShort":["Jan","Fev","Mar","Abr","Mai","Jun","Jul","Ago","Set","Out","Nov","Dez"] ,"firstWeekDay":1,"weekDayLabels":["Domingo","Segunda\u002Dfeira","Terça\u002Dfeira","Quarta\u002Dfeira","Quinta\u002Dfeira","Sexta\u002Dfeira","Sábado"] ,"weekDayLabelsShort":["Dom","Seg","Ter","Qua","Qui","Sex","Sáb"] } );
				new RichFaces.ui.Calendar("j_idt35", "pt_BR",
					{"datePattern":"dd\/M\/yy HH:mm:ss","currentDate":new Date(2011,11,20),"style":"z\u002Dindex: 3"} ).load();</script></span></span><input type="checkbox" name="j_idt36" />Somente ativos<input type="button" onclick="window.location.href='/rd/list.xhtml'; return false;" value="Atualizar" /></div></div>
<form id="formGeral" name="formGeral" method="post" action="/rd/list.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="formGeral" value="formGeral" />
<span id="formGeral:groupLink"><a href="#" onclick="mojarra.jsfcljs(document.getElementById('formGeral'),{'formGeral:j_idt39':'formGeral:j_idt39'},'');return false">Novo</a><a href="#" onclick="mojarra.jsfcljs(document.getElementById('formGeral'),{'formGeral:j_idt40':'formGeral:j_idt40'},'');return false">Alterar</a><a href="#" onclick="mojarra.jsfcljs(document.getElementById('formGeral'),{'formGeral:j_idt41':'formGeral:j_idt41'},'');return false">Excluir</a></span><span id="formGeral:list"><table id="formGeral:pitsList" class="rf-dt"><colgroup span="3"></colgroup><tbody id="formGeral:pitsList:tb" class="rf-dt-b"><tr class="rf-dt-nd"><td colspan="3" class="rf-dt-nd-c" style="display: none;"></td></tr></tbody><tbody id="formGeral:pitsList:sc"><tr><td style="display: none"><script type="text/javascript">new RichFaces.ui.DataTable("formGeral:pitsList",{"ajaxEventOptions":{} } )</script></td></tr></tbody></table></span><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="9210525801667547557:-1121223774330608854" autocomplete="off" />
</form></td>
</tr>
</tbody>
</table>

				<div id="footerDiv"><span id="footer"><div class="rf-p " id="j_idt49"><div class="rf-p-b " id="j_idt49_body">Testando o  rodape 2</div></div></span>
				</div></body>
</html>
Z

Uma outra dúvida, o fato de eu estar usando o maven em conjunto com o jetty pode estar influenciando na localização dos beans mapeados com @ManagedBeans

estava lendo esse post https://bugs.eclipse.org/bugs/show_bug.cgi?id=288243 e os caras aparentam dizer isso, mas não entendi bem

Z

Galera, estou retornando ao problema pq ainda não consegui resolver. Leventei os seguintes pontos:

- Aparentemente o Jetty em conjunto com o maven e o JSF não consegue carregar as annotations do JSF (Até carrega se for feita umas intervenções manuais via api do Jetty)
- Então tentei usar o Tomcat com o pluggin do maven, mas o resultado foi o mesmo, a tela carrega, nenhum o erro acontece, porém o Managed bean associado a tela parece não ser carregado, não exibe as  minhas mensagens de teste que colocoquei para exibir no console, e nem mesmo para no debug.
- Como uma última tentativa criei um projeto fora do maven e executo no tomcat, acontece a mesma coisa.


  Eu estava usando a implementação do JSF mojarra versão 2.1.2, lendo a documentação vi que ela poderia não funcionar corretamente com o Tomcat e com o Jetty (funcionava bem com o Weblogic e glassfish), seria esse o motivo do problema? Deu uma olhada na versão mais recente do Mojarra, e no relese notes ainda é citado esse caso, por isso nem tentei baixar.

 Acredito eu que o MyFaces seria um "concorrente" ao Mojarra, estou certo? comecei a baixar ele ontem para fazer o teste hoje. Acreditam que com essa outra implementação seria possível instanciar o Managed bean de forma correta?
M

pow cara, não sei se tu já resolveu, mas faltou o teu

<f:view> 

   tua página

</f:view>

abraços!!

Criado 19 de dezembro de 2011
Ultima resposta 20 de mai. de 2012
Respostas 9
Participantes 3