Estou usando a dupla JSF+Facelets em um pequeno projeto para poder aprender mais sobre estes frameworks, mas não estou conseguindo fazer o submit na primeira tela que criei.
Depois de “apanhar” para entender como criar os templates e utilizá-los, consegui também usar o conceito de componentes, e criar fragmentos de código para poder reutilizá-los em outras páginas. A página “insereEquipamento.xhtml” utiliza os templates “default.xhtml” (esta utiliza o template do arquivo “menuSuperior.jspx”) e o componente gerado pelo arquivo “insereEquipamento.jspx”, como pode ser visto nos códigos abaixo:
insereEquipamento.xhtml (a tag my:insereEquipamento foi criada como componente pelo arquivo insereEquipamento.jspx, devidamente registrada no web.xml)
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:my="http://w3.go.ibge.gov.br/jsf/facelets">
<ui:composition template="/WEB-INF/templates/default.xhtml">
<ui:define name="titulo">Informe os valores abaixo</ui:define>
<ui:define name="corpoPagina">
<h:panelGrid columns="3" cellpadding="3" cellspacing="3">
<f:facet name="header">
<h:outputText value="Informe os valores abaixo:" styleClass="tituloFormulario" />
</f:facet>
<f:verbatim> </f:verbatim>
<f:verbatim> </f:verbatim>
<f:verbatim> </f:verbatim>
<my:insereEquipamento />
<f:verbatim> </f:verbatim>
<a4j:commandButton value="Confirmar" type="submit" actionListener="{ondeMB.inserirEquipamento}" />
<f:verbatim> </f:verbatim>
<f:verbatim> </f:verbatim>
<a4j:outputPanel ajaxRendered="true">
<h:messages id="mensagens" binding="#{ondeMB.mensagem}" globalOnly="true"
layout="table" errorClass="mensagemErro"/>
</a4j:outputPanel>
<f:verbatim> </f:verbatim>
</h:panelGrid>
</ui:define>
</ui:composition>
</html>
default.xhtml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<head>
<meta http-equiv="Content-Type" content="text/html, charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="scripts/estilo.css"/>
<link rel="stylesheet" type="text/css" href="scripts/links.css"/>
<!-- <script language="JavaScript" src="scripts/appOndeEsta.js" /> -->
<title><ui:insert name="titulo">Intranet UE/GO</ui:insert></title>
</head>
<body>
<a4j:form id="form1">
<!-- cabecalho da pagina -->
<div id="top">
<ui:insert name="header">
<div>
<!-- banner aqui -->
</div>
</ui:insert>
</div>
<!-- menu superior -->
<div id="menuSuperior">
<ui:insert name="menuSuperior">
<ui:include src="/WEB-INF/templates/menuSuperior.jspx" />
</ui:insert>
</div>
<!-- corpo da pagina -->
<div id="corpoPagina">
<ui:insert name="corpoPagina">
** inserir aqui o conteúdo desejado **
</ui:insert>
</div>
<!-- rodape da pagina -->
<div id="rodape">
<ui:insert name="rodape">
<p style="text-align:center">UE-GO ©2010</p>
</ui:insert>
</div>
</a4j:form>
</body>
</html>
menuSuperior.jspx
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<ui:composition>
<rich:toolBar>
<rich:dropDownMenu>
<f:facet name="label">
<h:outputText value="Início"/>
</f:facet>
<rich:menuItem value="Início" submitMode="ajax" onclick="document.location.href='index.jsf'"/>
</rich:dropDownMenu>
<rich:dropDownMenu>
<f:facet name="label">
<h:outputText value="Inserir"/>
</f:facet>
<rich:menuItem value="Equipamento" submitMode="ajax" onclick="document.location.href='insereEquipamento.jsf'"/>
</rich:dropDownMenu>
</rich:toolBar>
</ui:composition>
</html>
insereEquipamento.jspx
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<ui:composition>
<h:outputLabel value="Tipo:" for="tipo" styleClass="label" />
<h:selectOneMenu id="tipo" valueChangeListener="#{ondeMB.setTipoSelecionado}"
validator="#{ondeMB.validaTipo}" styleClass="listbox">
<f:selectItem itemLabel="-- selecione o tipo --"/>
<f:selectItems value="#{ondeMB.tipos}" />
<a4j:support event="onchange" focus="patrimoniosDigitados" />
</h:selectOneMenu>
<f:verbatim> </f:verbatim>
<h:outputLabel value="Patrimônios:" for="patrimoniosDigitados" styleClass="label"/>
<h:inputText id="patrimoniosDigitados" size="50" title="informe valores separados por vírgula" styleClass="textArea"/>
<a4j:commandButton value="Adicionar" type="button" actionListener="#{ondeMB.transferePatrimonios}" />
<f:verbatim> </f:verbatim>
<h:panelGrid columns="2">
<h:selectManyListbox id="patrimonios" size="10" required="true" requiredMessage="Infome os patrimônios"
title="use a tecla CTRL para marcar mais de um elemento" style="width:100px"
styleClass="listbox">
<f:selectItem itemLabel=" "/>
<f:selectItems value="#{ondeMB.patrimonios}" />
</h:selectManyListbox>
<h:panelGrid columns="1">
<a4j:commandButton value="Remover" type="button" actionListener="#{ondeMB.removerItemLista}"/>
<a4j:commandButton value=" Limpar " type="button" actionListener="#{ondeMB.limparLista}"/>
</h:panelGrid>
</h:panelGrid>
<f:verbatim> </f:verbatim>
</ui:composition>
</html>
O meu problema é que o botão de submit presente na página “insereEquipamento.xhtml” não faz nada, não chama o managed bean como deveria.
Pesquisando na web (inclusive aqui) encontrei algumas referências sobre problemas de encadeamento de e evitei o uso de vários componentes aninhados, e optei por inserir um único a4j:form no template “default.xhtml”, o que insere todos os componentes em um único (o que constatei no HTML gerado. Tentei também utilizar o par tr:form tr:subform oferecido pelo MyFaces Trinidad, mas também não funcionou.
Peço ajuda aos colegas para me ajudarem a descobrir o que estou fazendo errado.
Estou utilizando MyFaces 1.2.5, RichFaces 3.2.2 SR1 no Tomcat 6.0.16.