Dúvidas com mensagens após executar métodos no JSF

5 respostas
vilmar_ferreira

Primeiramente boa tarde a todos.
Bem, é o seguinte, estou começando com JSF. Gostaria de saber como que faço para que uma mensagem apareça na tela após eu executar um método. Por exemplo o método de inserção no B.D.

Voltando uns anos atrás. Quando programávamos em JSP, eu faria ± assim:

se o método create(de inserção fosse) fosse booleano.

if(classe.create()){
    out.print("Dados incluídos com sucesso!");
}else{
    out.print("Deu erro");
}

Um exemplo bem simples este.

Estava tentando fazer algo parecido em jsf. Tento fazer algo que apareça no <h:message />.

Mas não estou conseguindo. Alguém pode me dar uma idéia de como fazer isso?

Desde já agradeço a atenção.

5 Respostas

juniorsatanas

ta usando RickFaces xhtml ?

vilmar_ferreira

richfaces jsp

juniorsatanas
&lt;?xml version="1.0" encoding="ISO-8859-1"?&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: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"&gt;
    &lt;style type="text/css"&gt;
        .ecol1 { vertical-align: top; padding-right : 25px }
        .ecol2 { vertical-align: top; border-left: #ACBECE 1px solid; padding-left : 10px }
        .rich-calendar-tool-btn{
            font-family: Arial, Verdana;
        }
    &lt;/style&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /&gt;
        &lt;link rel="StyleSheet" type="text/css" href="../style/estilos.css" media="screen" /&gt;
    &lt;/head&gt;
    &lt;a4j:keepAlive beanName="pessoaMB" /&gt;
    &lt;ui:composition template="/template/template.xhtml"&gt;
        &lt;ui:define name="corpo"&gt;
            &lt;rich:tabPanel switchType="ajax"&gt;
                &lt;rich:tab label="Cadastro de Pessoa"&gt;
                    &lt;a4j:form&gt;
                        &lt;rich:messages /&gt;
                        &lt;legend&gt;Cadastro de Pessoa&lt;/legend&gt;
                        &lt;a4j:region id="regiaoAjax"&gt;
                            &lt;a4j:status id="sts"&gt;
                                &lt;f:facet name="start"&gt;
                                    &lt;h:graphicImage value="/images/ajax-loader_1.gif" /&gt;
                                &lt;/f:facet&gt;
                            &lt;/a4j:status&gt;
                        &lt;/a4j:region&gt;
                        
                        &lt;!-- INICIA FORMULARIO--&gt;
                        
                        &lt;fieldset&gt;
                            &lt;h:panelGrid columns="2" id="inputs"&gt;

                                &lt;h:outputLabel for="matricula" value="Digite a Matrícula: " /&gt;
                                
                                &lt;h:inputText id="matriuclaInput" value="#{pessoaMB.pessoa.matricula}" &gt;
                                 &lt;a4j:commandButton value="Pesquisar" action="#{pessoaMB.pesquisaByMatricula}" reRender="pessoas"&gt;
                                 &lt;/a4j:commandButton&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="nome" value="Digite o Nome: " /&gt;
                                &lt;h:inputText id="nomeInput" value="#{pessoaMB.pessoa.nome}" styleClass="inputPesquisa"  &gt;

                                &lt;/h:inputText&gt;

                                &lt;h:outputLabel for="digina" value="Digina.: "  /&gt;
                                &lt;h:inputText id="digina" value="#{pessoaMB.pessoa.digina}" styleClass="edit" size="30"&gt;

                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="email" value="E-mail.:"  /&gt;
                                &lt;h:inputText id="email" value="#{pessoaMB.pessoa.email}"  styleClass="edit" size="40"&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="cpf" value="CPF.:"  /&gt;
                                &lt;h:inputText id="cpf" value="#{pessoaMB.pessoa.cpf}" styleClass="edit" size="15"&gt;
                                    &lt;rich:jQuery selector="#cpf" query="mask('[CPF removido]')" timing="onload"/&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="RG" value="RG"  /&gt;
                                &lt;h:inputText id="RG" value="#{pessoaMB.pessoa.RG}" styleClass="edit" size="20"&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="orgao_exp" value="Orgao Exp.:"  /&gt;
                                &lt;h:inputText id="orgao_exp" value="#{pessoaMB.pessoa.orgao_exp}" styleClass="edit" size="20"&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="titulo_ele" value="Titulo Eleitor.:"  /&gt;
                                &lt;h:inputText id="titulo_ele" value="#{pessoaMB.pessoa.titulo_ele}" styleClass="edit" size="30"&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="endereco" value="Endereco.:"/&gt;
                                &lt;h:inputText id="endereco" value="#{pessoaMB.pessoa.endereco}" styleClass="edit" size="40"&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="bairro" value="Bairro.:"/&gt;
                                &lt;h:inputText id="bairro" value="#{pessoaMB.pessoa.bairro}" styleClass="edit" size="40"&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="uf" value="UF.:"/&gt;
                                &lt;rich:comboBox defaultLabel="" id="uf" value="#{pessoaMB.pessoa.uf}" &gt;
                                    &lt;f:selectItem itemValue="AC"/&gt;
                                    &lt;f:selectItem itemValue="AL" /&gt;
                                    &lt;f:selectItem itemValue="AM" /&gt;
                                    &lt;f:selectItem itemValue="AP"/&gt;
                                    &lt;f:selectItem itemValue="BA" /&gt;
                                    &lt;f:selectItem itemValue="CE" /&gt;
                                    &lt;f:selectItem itemValue="DF" /&gt;
                                    &lt;f:selectItem itemValue="ES"/&gt;
                                    &lt;f:selectItem itemValue="FN"/&gt;
                                    &lt;f:selectItem itemValue="GO" /&gt;
                                    &lt;f:selectItem itemValue="MA" /&gt;
                                    &lt;f:selectItem itemValue="MG" /&gt;
                                    &lt;f:selectItem itemValue="MS" /&gt;
                                    &lt;f:selectItem itemValue="MT" /&gt;
                                    &lt;f:selectItem itemValue="PA" /&gt;
                                    &lt;f:selectItem itemValue="PB" /&gt;
                                    &lt;f:selectItem itemValue="PE"/&gt;
                                    &lt;f:selectItem itemValue="PI"/&gt;
                                    &lt;f:selectItem itemValue="PR" /&gt;
                                    &lt;f:selectItem itemValue="RJ" /&gt;
                                    &lt;f:selectItem itemValue="RN"/&gt;
                                    &lt;f:selectItem itemValue="RO" /&gt;
                                    &lt;f:selectItem itemValue="RR" /&gt;
                                    &lt;f:selectItem itemValue="RS"/&gt;
                                    &lt;f:selectItem itemValue="SC" /&gt;
                                    &lt;f:selectItem itemValue="SE"/&gt;
                                    &lt;f:selectItem itemValue="SP"/&gt;
                                    &lt;f:selectItem itemValue="TO" /&gt;
                                &lt;/rich:comboBox&gt;
                                &lt;h:outputLabel for="cidade" value="Cidade.:"/&gt;
                                &lt;h:inputText id="cidade" value="#{pessoaMB.pessoa.cidade}" styleClass="edit" size="40"&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="fone" value="Fone.:"/&gt;
                                &lt;h:inputText id="fone" value="#{pessoaMB.pessoa.fone}" styleClass="edit" size="15"&gt;
                                    &lt;rich:jQuery selector="#fone" query="mask('([telefone removido]')" timing="onload"/&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="celular" value="Tel. Celular.:"/&gt;
                                &lt;h:inputText id="celular" value="#{pessoaMB.pessoa.celular}" styleClass="edit" size="15"&gt;
                                    &lt;rich:jQuery selector="#celular" query="mask('([telefone removido]')" timing="onload"/&gt;
                                &lt;/h:inputText&gt;
                                &lt;h:outputLabel for="Data Nascimento.:" value="Data Nascimento.: "  /&gt;
                                &lt;rich:calendar id="data_nasc" value="#{pessoaMB.pessoa.data_nasc}"&gt;
                                    &lt;a4j:support event="ondateselected" /&gt;
                                &lt;/rich:calendar&gt;
                                &lt;h:outputLabel for="Data Nascimento.:" value="Data Matricula.: "  /&gt;
                                &lt;rich:calendar id="data_matricula" value="#{pessoaMB.pessoa.data_matricula}"&gt;
                                    &lt;a4j:support event="ondateselected" /&gt;
                                &lt;/rich:calendar&gt;
                                &lt;h:outputLabel for="id" value="CÓDIGO.: "  /&gt;
                                &lt;h:inputText id="id" value="#{pessoaMB.pessoa.id}" styleClass="inputPesquisa3" size="3" &gt;
                                &lt;/h:inputText&gt;
                            &lt;/h:panelGrid&gt;
                            
                            |&lt;a4j:commandButton value="Inserir" action="#{pessoaMB.save}" status="sts" reRender="inputs,fisicas,pessoas" styleClass="botoes"/&gt;
                            |&lt;a4j:commandButton value="Deletar" action="#{pessoaMB.delete}" status="sts" reRender="inputs,fisicas,pessoas" styleClass="botoes"/&gt;
                            |&lt;a4j:commandButton value="Modificar" action="#{pessoaMB.merge}" status="sts" reRender="inputs,fisicas,pessoas" styleClass="botoes"/&gt;
                            |&lt;a4j:commandButton value="Menslidades" action="toCadastraMensalidade" status="sts" reRender="inputs,fisicas,pessoas" styleClass="botoes"/&gt;
                            |&lt;a4j:commandButton value="Voltar" immediate="true" action="toIndex" styleClass="botoes"/&gt;|

                        &lt;/fieldset&gt;
                        &lt;rich:messages /&gt;
                        &lt;fieldset&gt;&lt;legend&gt;Atualização de Dados&lt;/legend&gt;
                            &lt;f:subview id="listauser"&gt;

                                &lt;rich:dataTable value="#{pessoaMB.pessoas}" var="pessoa" rows="5" id="pessoas" width="100%" cellspacing="0" cellpadding="0" border="5"&gt;
                                    &lt;h:column&gt;
                                        &lt;f:facet name="header"&gt;
                                            &lt;h:outputText value="MATRÍCULA" /&gt;
                                        &lt;/f:facet&gt;
                                        &lt;h:outputText value="#{pessoa.matricula}" /&gt;
                                    &lt;/h:column&gt;
                                    &lt;h:column&gt;
                                        &lt;f:facet name="header"&gt;
                                            &lt;h:outputText value="NOME" /&gt;
                                        &lt;/f:facet&gt;
                                        &lt;h:outputText value="#{pessoa.nome}" /&gt;
                                    &lt;/h:column&gt;
                                    &lt;h:column&gt;
                                        &lt;f:facet name="header"&gt;
                                            &lt;h:outputText value="E-MAIL" /&gt;
                                        &lt;/f:facet&gt;
                                        &lt;h:outputText value="#{pessoa.email}" /&gt;
                                    &lt;/h:column&gt;
                                    &lt;h:column&gt;
                                        &lt;f:facet name="header"&gt;
                                            &lt;h:outputText value="CPF" /&gt;
                                        &lt;/f:facet&gt;
                                        &lt;h:outputText value="#{pessoa.cpf}" /&gt;
                                    &lt;/h:column&gt;
                                    &lt;h:column&gt;
                                        &lt;f:facet name="header"&gt;
                                            &lt;h:outputText value="DATA NASC." /&gt;
                                        &lt;/f:facet&gt;
                                        &lt;h:outputText value="#{pessoa.data_nasc}"&gt;
                                            &lt;f:convertDateTime pattern="dd/MM/yyyy" /&gt;
                                        &lt;/h:outputText&gt;
                                    &lt;/h:column&gt;
                                    &lt;h:column&gt;
                                        &lt;f:facet name="header"&gt;
                                            &lt;h:outputText value="CELULAR" /&gt;
                                        &lt;/f:facet&gt;
                                        &lt;h:outputText value="#{pessoa.celular}" /&gt;
                                    &lt;/h:column&gt;
                                    &lt;h:column&gt;
                                        &lt;f:facet name="header"&gt;
                                            &lt;h:outputText value="Excluir"/&gt;
                                        &lt;/f:facet&gt;
                                        &lt;a4j:commandLink action="#{pessoaMB.delete}" status="sts" reRender="inputs,fisicas,pessoas" &gt;
                                            &lt;h:outputText value="Excluir"/&gt;
                                            &lt;f:setPropertyActionListener value="#{pessoa.id}" target="#{pessoaMB.id}" /&gt; &lt;!-- pega  o id --&gt;
                                        &lt;/a4j:commandLink&gt;
                                    &lt;/h:column&gt;

                                    &lt;h:column&gt;
                                        &lt;f:facet name="header"&gt;
                                            &lt;h:outputText value="Editar"/&gt;
                                        &lt;/f:facet&gt;
                                        &lt;a4j:commandLink reRender="inputs,fisicas,pessoas" &gt;
                                            &lt;h:outputText value="Editar"/&gt;
                                            &lt;f:setPropertyActionListener value="#{pessoa}" target="#{pessoaMB.pessoa}" /&gt;
                                        &lt;/a4j:commandLink&gt;
                                    &lt;/h:column&gt;

                                    &lt;f:facet name="footer"&gt;
                                        &lt;rich:datascroller /&gt;
                                    &lt;/f:facet&gt;
                                &lt;/rich:dataTable&gt;

                            &lt;/f:subview&gt;
                        &lt;/fieldset&gt;
                    &lt;/a4j:form&gt;
                &lt;/rich:tab&gt;
                &lt;!-- ****************************************************************** TAB LISTA DE PESSOAS********************************************--&gt;
                &lt;rich:tab label="Lista de Pessoas"&gt;
                    &lt;f:subview id="listauser"&gt;
                        &lt;a4j:form&gt;
                            &lt;rich:messages /&gt;
                            &lt;fieldset&gt;
                                &lt;a4j:region id="regiaoAjax"&gt;
                                    &lt;a4j:status id="sts"&gt;
                                        &lt;f:facet name="start"&gt;
                                            &lt;h:graphicImage value="/images/ajax-loader_1.gif" /&gt;
                                        &lt;/f:facet&gt;
                                    &lt;/a4j:status&gt;
                                &lt;/a4j:region&gt;
                                &lt;h:panelGrid columns="1" id="inputs"&gt;
                                    
                                    &lt;h:outputLabel for="nomeLabel" value="Digite o Nome: " /&gt;
                                      &lt;a4j:commandButton value="Pesquisar" action="#{pessoaMB.pesquisaByNome}" reRender="pessoas"&gt;
                                        &lt;/a4j:commandButton&gt;
                                    &lt;h:inputText id="nomeInput" value="#{pessoaMB.pessoa.nome}" style=" width : 250px;"  styleClass="inputPesquisa"&gt;
                                      
                                    &lt;/h:inputText&gt;

                                    &lt;h:outputLabel for="matriculaLabel" value="Digite a Matrícula: " /&gt;
                                      &lt;a4j:commandButton value="Pesquisar" action="#{pessoaMB.pesquisaByMatricula}" reRender="pessoas"&gt;
                                        &lt;/a4j:commandButton&gt;
                                    &lt;h:inputText id="matriculaInput" value="#{pessoaMB.pessoa.matricula}" style=" width : 250px;"  styleClass="inputPesquisa"&gt;
                                      
                                    &lt;/h:inputText&gt;
                                    
                                        &lt;h:outputLabel for="diginaLabel" value="Digite a Digina: " /&gt;
                                         &lt;a4j:commandButton value="Pesquisar" action="#{pessoaMB.pesquisaByDigina}" reRender="pessoas"&gt;
                                            &lt;/a4j:commandButton&gt;
                                        &lt;h:inputText id="diginaInput" value="#{pessoaMB.pessoa.digina}" style=" width : 250px;"  styleClass="inputPesquisa"&gt;
                                           
                                        &lt;/h:inputText&gt;
                                &lt;/h:panelGrid&gt;
                            &lt;/fieldset&gt;
                            &lt;rich:dataTable value="#{pessoaMB.pessoas}" var="pessoa" reRender="ds" rows="30" id="pessoas" width="100%" cellspacing="0" cellpadding="0" border="1"&gt;
                                                                        
                                &lt;h:column&gt;
                                    &lt;f:facet name="header"&gt;
                                        &lt;h:outputText value="MATRÍCULA" /&gt;
                                    &lt;/f:facet&gt;
                                    &lt;h:outputText value="#{pessoa.matricula}" /&gt;
                                &lt;/h:column&gt;
                                &lt;h:column&gt;
                                    &lt;f:facet name="header"&gt;
                                        &lt;h:outputText value="NOME" /&gt;
                                    &lt;/f:facet&gt;
                                    &lt;h:outputText value="#{pessoa.nome}" /&gt;
                                &lt;/h:column&gt;
                                &lt;h:column&gt;
                                    &lt;f:facet name="header"&gt;
                                        &lt;h:outputText value="E-MAIL" /&gt;
                                    &lt;/f:facet&gt;
                                    &lt;h:outputText value="#{pessoa.email}" /&gt;
                                &lt;/h:column&gt;
                                &lt;h:column&gt;
                                    &lt;f:facet name="header"&gt;
                                        &lt;h:outputText value="CPF" /&gt;
                                    &lt;/f:facet&gt;
                                    &lt;h:outputText value="#{pessoa.cpf}" /&gt;
                                &lt;/h:column&gt;
                                &lt;h:column&gt;
                                    &lt;f:facet name="header"&gt;
                                        &lt;h:outputText value="DATA NASC." /&gt;
                                    &lt;/f:facet&gt;
                                    &lt;h:outputText value="#{pessoa.data_nasc}"&gt;
                                        &lt;f:convertDateTime pattern="dd/MM/yyyy" /&gt;
                                    &lt;/h:outputText&gt;
                                &lt;/h:column&gt;
                                &lt;h:column&gt;
                                    &lt;f:facet name="header"&gt;
                                        &lt;h:outputText value="CELULAR" /&gt;
                                    &lt;/f:facet&gt;
                                    &lt;h:outputText value="#{pessoa.celular}" /&gt;
                                &lt;/h:column&gt;
                               
                                &lt;f:facet name="footer"&gt;
                                    &lt;rich:datascroller /&gt;
                                &lt;/f:facet&gt;
                            &lt;/rich:dataTable&gt;
                        &lt;/a4j:form&gt;

                    &lt;/f:subview&gt;
                &lt;/rich:tab&gt;
                &lt;!-- ******************************FIM************************************ TAB LISTA DE PESSOAS********************************************--&gt;
                &lt;rich:tab label="Filtros"&gt;
                    &lt;h:form&gt;
                        &lt;rich:dataTable value="#{pessoaMB.pessoas}" var="cap" rows="10" reRender="ds" id="simpletable" &gt;
                            &lt;f:facet name="header"&gt;
                                &lt;rich:columnGroup&gt;
                                    &lt;rich:column colspan="2" &gt;
                                        &lt;h:outputText value="FILTROS DE PESSOAS"/&gt;
                                    &lt;/rich:column&gt;
                                    &lt;rich:column breakBefore="true"&gt;
                                        &lt;h:outputText value="Nome"/&gt;
                                    &lt;/rich:column&gt;
                                    &lt;rich:column&gt;
                                        &lt;h:outputText value="Matricula"/&gt;
                                    &lt;/rich:column&gt;
                                     &lt;rich:column&gt;
                                        &lt;h:outputText value="Digina"/&gt;
                                    &lt;/rich:column&gt;
                                      &lt;rich:column&gt;
                                        &lt;h:outputText value="Email"/&gt;
                                    &lt;/rich:column&gt;
                                     &lt;rich:column&gt;
                                        &lt;h:outputText value="CPF"/&gt;
                                    &lt;/rich:column&gt;
                                     &lt;rich:column&gt;
                                        &lt;h:outputText value="Data/Nascimento"/&gt;
                                    &lt;/rich:column&gt;
                                     &lt;rich:column&gt;
                                        &lt;h:outputText value="Celular"/&gt;
                                    &lt;/rich:column&gt;
                                &lt;/rich:columnGroup&gt;
                            &lt;/f:facet&gt;

                            &lt;rich:column filterBy="#{cap.nome}" filterEvent="onkeyup" filterValue="#{pessoaMB.pessoa.nome}"&gt;
                                &lt;h:outputText value="#{cap.nome}"/&gt;
                            &lt;/rich:column&gt;

                            &lt;rich:column filterBy="#{cap.matricula}" filterEvent="onkeyup" filterValue="#{pessoaMB.pessoa.matricula}"&gt;
                                &lt;h:outputText value="#{cap.matricula}"/&gt;
                            &lt;/rich:column&gt;


                             &lt;rich:column filterBy="#{cap.digina}" filterEvent="onkeyup" filterValue="#{pessoaMB.pessoa.digina}"&gt;
                                &lt;h:outputText value="#{cap.digina}"/&gt;
                            &lt;/rich:column&gt;
                            
                            &lt;rich:column filterBy="#{cap.email}" filterEvent="onkeyup" filterValue="#{pessoaMB.pessoa.email}"&gt;
                                &lt;h:outputText value="#{cap.email}"/&gt;
                            &lt;/rich:column&gt;

                            &lt;rich:column filterBy="#{cap.cpf}" filterEvent="onkeyup" filterValue="#{pessoaMB.pessoa.cpf}"&gt;
                                &lt;h:outputText value="#{cap.cpf}"/&gt;
                            &lt;/rich:column&gt;
                            
                            &lt;rich:column filterBy="#{cap.data_nasc}" filterEvent="onkeyup" filterValue="#{pessoaMB.pessoa.data_nasc}"&gt;
                                &lt;h:outputText value="#{cap.data_nasc}"/&gt;
                            &lt;/rich:column&gt;

                             &lt;rich:column filterBy="#{cap.celular}" filterEvent="onkeyup" filterValue="#{pessoaMB.pessoa.celular}"&gt;
                                &lt;h:outputText value="#{cap.celular}"/&gt;
                            &lt;/rich:column&gt;


                            &lt;f:facet name="footer"&gt;
                                &lt;rich:datascroller id="ds" renderIfSinglePage="false"&gt;&lt;/rich:datascroller&gt;
                            &lt;/f:facet&gt;
                        &lt;/rich:dataTable&gt;
                        &lt;!--&lt;a4j:commandButton action="#{capitalsBean.resetFilter}" value="Reset Current Filtering" reRender="simpletable" ajaxSingle="true" limitToList="true"/&gt; --&gt;
                    &lt;/h:form&gt;
                &lt;/rich:tab&gt;

                &lt;rich:tab label="Relatórios"&gt;

                    |&lt;a4j:commandButton value="Relatorio Pessoas" immediate="true" action="toIn1" styleClass="botoes"/&gt;|
                    |&lt;a4j:commandButton value="Relatorio Pessoas Data Nascimento" immediate="true" action="toIn2" styleClass="botoes"/&gt;|
                    |&lt;a4j:commandButton value="Relatorio Pessoas Digina" immediate="true" action="toIn3" styleClass="botoes"/&gt;|
                    |&lt;a4j:commandButton value="Relatorio Pessoas Matrícula" immediate="true" action="toIn4" styleClass="botoes"/&gt;|

                &lt;/rich:tab&gt;
            &lt;/rich:tabPanel&gt;
        &lt;/ui:define&gt;
    &lt;/ui:composition&gt;
&lt;/html&gt;
vilmar_ferreira

Opa. Não entendi muito quando as mensagens do método irão aparecer na aplicação, pode me explicar??

Ah, gostei dessa parte, até coloquei na minha aplicação :slight_smile:

<a4j:region id=“regiaoAjax”>
<a4j:status id=“sts”>
<f:facet name=“start”>
<h:graphicImage value="/images/ajax-loader_1.gif" />
</f:facet>
</a4j:status>
</a4j:region>

Mas como estou fazendo tudo em ajax a imagem aparece muito rápido. Temo como colocar um tempo mínimo para que ela fique aparecendo em cada requisição??

Parabéns pelo seu código.

vilmar_ferreira

Olha como o meu está. Estou com dois problemas para terminar esta tela. Estou fazendo como você, todas as operações faço na mesma tela.

Meu primeiro problema é, como tenho um campo obrigatório (required=“true”) não consigo editar. Ele sempre pede “rg obrigatório”.

<h:outputText value="RG:"/>
						<h:inputText id="rg" value="#{PessoaView.pes.rg}" required="#{PessoaView.reqValid}" requiredMessage="RG é obrigatório!">
							<rich:ajaxValidator event="onblur"/>
						</h:inputText>
						<rich:message for="rg"/>

Aqui está meu link editar. Que no caso carregaria o formulário com os registros do banco de dados. Mas como o rg é obrigatório não deixa de jeito nenhum. Quando coloco immediate = “true” no link só carrega o id.

<a4j:commandLink reRender="painelCadastro,grid" action="#{PessoaView.testaBotao}">
								<h:graphicImage styleClass="link" url="imagens/rtg_rate.gif" title="Alterar"/>
								<f:setPropertyActionListener value="#{item}" target="#{PessoaView.pes}"/>
							</a4j:commandLink>

E o segundo problema é quanto as mensagem quando executo os métodos. Como que faz pra quando um método é executado aparecer uma mensagem da situação dele. Se deu certo ou não.

Abaixo está todo meu código.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	    pageEncoding="ISO-8859-1"%>
	    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
	    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
	    <%@taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
	    <%@taglib uri="http://richfaces.org/rich" prefix="rich" %>
	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
	<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Pessoa</title>
	<style type="text/css">
		.linha_a{
			background-color: #C6E2FF;
			text-align: center;
			padding: 8px;
			font-family: Arial;
			font-size: 12px;
			
		}
		.linha_b{
			background-color: white;
			text-align: center;
			padding: 8px;
			font-family: Arial;
			font-size: 12px;
		}
		.tabela{
			
			margin-left: auto;
			margin-right: auto;
			width: 600px;
		}
		.cabecalho{
			text-align: center;
			color: black;
			background: white;
			font-family: Arial;
			font-size: 12px;
			padding:5px;
		}
		.cabecalhoCad{
			PADDING-RIGHT: 3px; 
		PADDING-LEFT: 3px;
		background-color: #31659C;
		font-size: 11px; 
		COLOR: #ffffff;
		font-weight: bol
		}
		.linhasCad{
			background-color: white;
			font-family: Arial;
			font-size: 12px;
		}
		.tabelaCad{
			width: 600px;
			margin-left: auto;
			margin-right: auto;
		}
		.botao{
			background-color: #104E8B;
			color: white;
			border-color: black;
			
		}
		.tabelaBot{
			margin-left: auto;
			margin-right: auto;
		}
		.link{
			border: none;
			
		}
		.field {
		PADDING-RIGHT: 3px; 
		PADDING-LEFT: 3px; 
		PADDING-BOTTOM: 2px; 
		PADDING-TOP: 2px }
		.label {
		PADDING-RIGHT: 3px; 
		PADDING-LEFT: 3px; 
		PADDING-BOTTOM: 2px; 
		PADDING-TOP: 2px;
		background-color: #f6f6f6;
		text-align:right }

	</style>
	</head>
	<body>
	<f:view>
		<rich:tabPanel switchType="client" id="abasCadastro">
			<rich:tab label="Home">
				novo
			</rich:tab>
			<rich:tab label="Pessoa" id="Pessoa">
				<h:form id="cadastro">
					
					<h:panelGrid columnClasses="label, field" id="painelCadastro" styleClass="tabelaCad" headerClass="cabecalhoCad" border="0" columns="3">
						<f:facet name="header">
							<h:outputText value="Pessoa"/>
						</f:facet>
						<h:outputText value="Identificador:"/>
						<h:inputText id="identificador" value="#{PessoaView.pes.identificador}" disabled="true"/>
						<h:message for="identificador"/>
						<h:outputText value="RG:"/>
						<h:inputText id="rg" value="#{PessoaView.pes.rg}" required="#{PessoaView.reqValid}" requiredMessage="RG é obrigatório!">
							<rich:ajaxValidator event="onblur"/>
						</h:inputText>
						<rich:message for="rg"/>
						<h:outputText value="Município:"/>
						<h:inputText id="municipio" value="#{PessoaView.pes.municipio}"/>
						<h:message for="municipio"/>
						<h:outputText value="Órgão Expeditor:"/>
						<h:inputText id="rgorgaoexp" value="#{PessoaView.pes.rgorgaoexp}"/>
						<h:message for="rgorgaoexp"/>
						<h:outputText value="Data Emissão RG:"/>
						<rich:calendar id="rgemissao" value="#{PessoaView.pes.rgemissao}" datePattern="yyyy-MM-dd" converter="converteAnoMySQL"/>
						<h:message for="rgemissao"/>
						<h:outputText value="CPF:"/>
						<h:inputText id="cpf" value="#{PessoaView.pes.cpf}"/>
						<h:message for="cpf"/>
						<h:outputText value="Sexo:"/>
						<h:inputText maxlength="1" id="sexo" value="#{PessoaView.pes.sexo}"/>
						<h:message for="sexo"/>
						<h:outputText value="Título Eleitoral:"/>
						<h:inputText id="titeleitoral" value="#{PessoaView.pes.titeleitoral}"/>
						<h:message for="titeleitoral"/>
						<h:outputText value="Email:"/>
						<h:inputText id="email" value="#{PessoaView.pes.email}"/>
						<h:message for="email"/>
						<h:outputText value="Endereço:"/>
						<h:inputText id="endereco" value="#{PessoaView.pes.endereco}"/>
						<h:message for="endereco"/>
						<h:outputText value="#{PessoaView.reqValid}"/>
					
					
					</h:panelGrid>
					
					<br />
					<h:panelGrid columns="5" styleClass="tabelaBot" id="grid">
						<a4j:commandButton value="Cadastrar" status="sts" id="botCadastrar" rendered="#{PessoaView.botCad}" styleClass="botao" reRender="painel" action="#{PessoaView.create}"/>
						<a4j:commandButton value="Alterar" id="botAlterar" rendered="#{PessoaView.botAlt}" styleClass="botao" reRender="painel" action="#{PessoaView.update}"/>
						<a4j:commandButton status="sts" value="Listar" immediate="true" reRender="painel" styleClass="botao" action="#{PessoaView.mudaListar}" />
						<a4j:commandButton value="Limpar" styleClass="botao" reRender="painelCadastro, grid" action="#{PessoaView.limpa}"/>
					
					</h:panelGrid>
										
					<br />
					<rich:messages />
					<a4j:region id="regiaoAJAX">
						<a4j:status id="sts">
							<f:facet name="start">
								<h:graphicImage value="/imagens/AJAX_03.gif" />
							</f:facet>
						</a4j:status>
					</a4j:region>
					<br />
			
					<rich:panel id="painel" style="border:none;">
					
					<rich:dataTable id="listaCliente" rows="5" rowClasses="linha_a, linha_b" styleClass="tabela" headerClass="cabecalho"  value="#{PessoaView.allPessoas}" var="item"
					 rendered="#{PessoaView.listar}" cellpadding="2" cellspacing="0">
						<f:facet name="header">
							<h:outputText value="Pessoas Cadastradas"/>
						</f:facet>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="RG"/> 
							</f:facet>
							<h:outputText value="#{item.rg}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Municipio"/> 
							</f:facet>
							<h:outputText value="#{item.municipio}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="CPF"/>
							</f:facet>
							<h:outputText value="#{item.cpf}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Sexo"/>
							</f:facet>
							<h:outputText value="#{item.sexo}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="E-Mail"/>
							</f:facet>
							<h:outputText value="#{item.email}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Operação"/>
							</f:facet>
							
							<a4j:commandLink reRender="painelCadastro,grid" action="#{PessoaView.testaBotao}">
								<h:graphicImage styleClass="link" url="imagens/rtg_rate.gif" title="Alterar"/>
								<f:setPropertyActionListener value="#{item}" target="#{PessoaView.pes}"/>
							</a4j:commandLink>
							&nbsp;&nbsp;
							<a4j:commandLink immediate="true" reRender="painel" action="#{PessoaView.delete}">
								<h:graphicImage styleClass="link" url="imagens/bRmv.gif" title="Apagar"/>
								<f:setPropertyActionListener value="#{item.identificador}" target="#{PessoaView.identificador}"/>
							</a4j:commandLink>
						
						</rich:column>
						<f:facet name="footer">
							<rich:datascroller id="paginacao" for="listaCliente" rendered="#{PessoaView.listar}"/>
						</f:facet>
					</rich:dataTable>
					</rich:panel>
					
			
				</h:form>
			</rich:tab>
	
		</rich:tabPanel>
	
		
	</f:view>
	</body>
	</html>

Desde já agradeço a atenção.

Abraço

Criado 29 de abril de 2010
Ultima resposta 30 de abr. de 2010
Respostas 5
Participantes 2