Pessoal…
estou codificando um exemplo simples de CRUD utlizando facelets e RichFaces, mas acredito que esteja com algum problema de renderização no bloco de edição.
O que acontece?
Ao acessar a página do sistema, a aplicacao se inicia no bloco de pesquisa e abre a possibilidade de adicionar um novo item.
Após clicar no item, o bloco de edição é renderizado, e o usuário pode preencher os campos para cadastramento do item no banco de dados.
Aí começam os problemas.
Neste bloco qualquer um, dos dois botões existentes, fazem o submit do form, mas não executam a action que estão programados para executar.
Alguém já passou por este problema?
Abaixo segue o código do template aplicação.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:t="http://myfaces.apache.org/tomahawk">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>
<ui:insert name="title">
Beta Version
</ui:insert>
</title>
<ui:insert name="head">
</ui:insert>
<script type="text/javascript">
var infoWindowAMShown = false;
var infoWindowAMTimer;
function showModalInfoWindow()
{
infoWindowAMTimer = setTimeout("if(!infoWindowAMShown){Richfaces.showModalPanel('ajaxLoadingModalBox');infoWindowAMShown=true;}", 500);
}
function hideModalInfoWindow()
{
if (infoWindowAMShown) {
Richfaces.hideModalPanel('ajaxLoadingModalBox');
infoWindowAMShown=false;
} else {
if(infoWindowAMTimer)
clearTimeout(infoWindowAMTimer);
}
}
</script>
</head>
<body>
<!-- ajax loading -->
<a4j:status onstart="showModalInfoWindow();" onstop="hideModalInfoWindow()"/>
<rich:modalPanel id="ajaxLoadingModalBox" autosized="true">
<f:facet name="header">
<h:outputText value="Em processamento"/>
</f:facet>
<h:outputText value="Por favor aguarde... Sua solicitação está sendo processada pelo sistema!"/>
</rich:modalPanel>
<!-- bloco principal -->
<a4j:outputPanel ajaxRendered="true" id="mainOutputPanel" style="width: 600px">
<a4j:form>
<!-- bloco de pesquisa -->
<rich:panel id="searchlistBlock"
rendered="#{defaultBean.pesquisarEstado}">
<f:facet name="header">
Pesquisar
</f:facet>
<h:messages errorStyle="color: red" infoStyle="color: blue" layout="table" showSummary="true" showDetail="false" globalOnly="true"/>
<ui:insert name="searchlistBlock">
</ui:insert>
</rich:panel>
<!-- bloco de edicao -->
<rich:panel id="addUpdateBlock"
rendered="#{defaultBean.adicionarEstado or defaultBean.editarEstado}">
<f:facet name="header">
Dados do Bean
</f:facet>
<h:messages errorStyle="color: red" infoStyle="color: blue" layout="table" showSummary="true" showDetail="false" globalOnly="true"/>
<ui:insert name="addUpdateBlock">
</ui:insert>
</rich:panel>
</a4j:form>
</a4j:outputPanel>
</body>
</html>
Abaixo o codigo da pagina renderizada
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/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"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:c="http://java.sun.com/jstl/core"
template="/templates/crudTemplate.xhtml">
<!-- passa parametro para o template -->
<ui:param name="defaultBean" value="#{holdingBean}" />
<ui:define name="title">
Cadastro de Holdings
<t:saveState id="_bean" value="#{holdingBean}" />
</ui:define>
<ui:define name="head">
<style type="text/css">
.odd-row {
background-color: #ECF3FE;
}
.even-row {
background-color: #FCFFFE;
}
</style>
</ui:define>
<!-- define searchlistBlock -->
<ui:define name="searchlistBlock">
<h:panelGrid columns="1">
<h:column>
<a4j:commandButton value="Pesquisar" action="#{holdingBean.pesquisar}"/>
<a4j:commandButton value="Adicionar" action="#{holdingBean.prepararParaAdicionar}" immediate="true"/>
<a4j:commandButton value="Gravar - I" action="#{holdingBean.incluir}" />
</h:column>
</h:panelGrid>
<rich:spacer width="1" height="5" />
<rich:datascroller align="left" for="userList" maxPages="10" />
<rich:spacer height="15" />
<rich:dataTable width="450" id="userList" rows="10"
rowClasses="odd-row,even-row"
columnClasses="col" value="#{holdingBean.holdings}" var="row">
<f:facet name="header">
<rich:columnGroup>
<h:column>
<h:outputText styleClass="headerText" value="ID" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="Nome" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="CNPJ" />
</h:column>
<h:column>
</h:column>
</rich:columnGroup>
</f:facet>
<h:column>
<h:outputText value="#{row.id}" />
</h:column>
<h:column>
<h:outputText value="#{row.nome}" />
</h:column>
<h:column>
<h:outputText value="#{row.CNPJ}" />
</h:column>
<h:column>
<span>
<a4j:commandLink value="Editar" action="#{holdingBean.prepararParaEditar}" immediate="true">
<f:setPropertyActionListener value="#{row}" target="#{holdingBean.holding}"/>
</a4j:commandLink>
</span>
<span>
<a4j:commandLink value="Excluir" action="#{holdingBean.excluir}" immediate="true">
<f:setPropertyActionListener value="#{row}" target="#{holdingBean.holding}"/>
</a4j:commandLink>
</span>
</h:column>
</rich:dataTable>
</ui:define>
<!-- define addUpdateBlock -->
<ui:define name="addUpdateBlock">
<h:panelGrid columns="2" id="panel2" binding="#{holdingBean.panelForm}" columnClasses="odd-row,even-row">
<h:outputLabel value="Nome: "/>
<h:column>
<h:inputText value="#{holdingBean.holding.nome}" size="30" required="true" id="nome"
requiredMessage="Por favor, informe um nome para a Holding"
readonly="#{holdingBean.editarEstado}"
style="#{holdingBean.editarEstado ? 'color: gray;' : ''}"/>
<br/>
<h:message for="nome" errorStyle="color: darkred;"/>
</h:column>
<h:outputLabel value="CNPJ: "/>
<h:column>
<h:inputText value="#{holdingBean.holding.numeroCNPJ}" size="14" required="false" id="numeroCNPJ"
readonly="#{holdingBean.editarEstado}"
style="#{holdingBean.editarEstado ? 'color: gray;' : ''}"/>
<br/>
</h:column>
</h:panelGrid>
<a4j:commandButton value="Gravar - I" action="#{holdingBean.incluir}" rendered="#{holdingBean.adicionarEstado}"/>
<a4j:commandButton value="Gravar - U" action="#{holdingBean.alterar}" rendered="#{holdingBean.editarEstado}"/>
<a4j:commandButton value="Voltar para pesquisa" action="#{holdingBean.voltar}" immediate="true"/>
</ui:define>
</ui:composition>
Abaixo, o código do Bean
import java.util.List;
import br.com.aresitsolutions.aps.businessobjects.HoldingBO;
import br.com.aresitsolutions.aps.domain.Holding;
import br.com.aresitsolutions.aps.domain.Usuario;
import br.com.aresitsolutions.aps.exception.BusinessException;
public class HoldingBean extends CrudBean {
private Usuario usuarioLogado;
private HoldingBO holdingBO;
private Holding holding;
private List<Holding> holdings;
public HoldingBean() {
super();
this.usuarioLogado = null;
holdingBO = new HoldingBO(this.usuarioLogado);
}
public List<Holding> getHoldings() {
return this.holdings;
}
public Holding getHolding() {
return holding;
}
public void setHolding(Holding holding) {
this.holding = holding;
}
public void setHoldings(List<Holding> holdings) {
this.holdings = holdings;
}
public void listar() throws BusinessException {
this.holdings = holdingBO.listar();
if (this.holdings == null || this.holdings.size() == 0) {
this.lancarMensagemInformacao("holding.cadastro.vazio");
}
}
public void inserir() throws BusinessException {
holdingBO.incluir(holding);
this.lancarMensagemInformacao("holding.cadastro.sucesso");
}
public void editar() throws BusinessException {
holdingBO.alterar(holding);
this.lancarMensagemInformacao("holding.alterado.sucesso");
}
public void apagar() throws BusinessException {
holdingBO.excluir(holding);
this.lancarMensagemInformacao("holding.excluido.sucesso");
}
public void limparCampos() {
holding = new Holding();
}
}
Abs.
Daniel