Navegação entre páginas JSF ( Problemão)

9 respostas
thiago.limma

Pessoal,

estou com um problema chato. Fiz duas jsps. Uma tem um botão, que quando eu clicar, teria que navegar para a outra página. Fiz a navegação no faces config.xml e na action do botão, coloquei o nome da navegação.

O problema é que quando clico no botão, tenho apenas um refresh na página e a navegação não funciona. Já olhei o web.xml, e o faces config.xml está setado direitinho.

A navegação entre páginas não funciona.

Alguém pode me salvar?

Abraço

9 Respostas

Giulliano

caraca…pode ser tanta coisa que não caberia aqui se fosse escrever…

esta dando alguma exception ?? se não verifique o faces config e os métodos no ManagedBean…

Luiz_Junior

Boa Tarde,

Cara posta sua jsp e suas configurações no faces.

thiago.limma

Bom, vamos lá

Jsp 1 :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%> 
<f:view>
    <html>
        <head>
            <meta http-equiv="Conten,0t-Type"
                  content="text/html; charset=windows-1252"/>
            <title>Mant&eacute;m Fiscal</title>
            
            <link type="text/css" rel="stylesheet"
                  href="../../Shared/estilos/corporativoCBEX.css"/>
            <script type="text/javascript"
                    src="../../Shared/scripts/corporativo.js"></script>
                     <style type="text/css">
      a {
            border:0;
        }
      </style>
        </head>
         <body>
         
    <img id="imgIndicador" src="../../Shared/imagens/imgIconeEspera.gif" class="imagemCentro" alt="espera"
                style="display:none" height="100" width="100">
        <div id="telaEspera" style="display:none">
        </div>
    
        
  <h:outputText value="#{actMantemFiscal.menuSistema}" escape="false"/>
        
        <h:form>
                <h:panelGrid columns="2" styleClass="msgErro"
                             style="display:none" id="tabelaMsgErro"
                             title="msgErroFixa">
                    <h:graphicImage url="/Web/Shared/imagens/imgIconeErro.gif"
                                    height="20" width="20"/>
                    <h:outputText value="O preenchimento do(s) campo(s) está incorreto."/>
                </h:panelGrid>
                <%=tcu.util.formatHtml.FormatHtmlJsf.retornaErrosContextObject()%>
                <%=tcu.util.formatHtml.FormatHtmlJsf.retornaAlertasContextObject()%>
                <%=tcu.util.formatHtml.FormatHtmlJsf.retornaInfosContextObject()%>
               
                    <br></br>
                    <h1>
                        &nbsp;
                        <t:outputText value="Pesquisa Contrato"/>
                    </h1>
                    
                    <span class="style2">&nbsp;&nbsp;</span>
                     
                    <table width="100%" border="0" cellspacing="0"
                           cellpadding="0" class="tabelaSemLateral">
                        <tr>
                            <td>
                                <table width="100%" border="0" cellspacing="0"
                                       cellpadding="0" class="tabela">
                                    <tr>
                                        <th colspan="2">
                                            <div align="left">
                                                <t:outputText value="Consultar Contrato"/>
                                            </div>
                                        </th>
                                    </tr>
                                    <tr>
                                        <td width="20%">
                                            <strong><t:outputText value="Número/Ano:"/></strong>
                                        </td>
                                        <td width="80%">
                                            <t:inputText value="#{actMantemFiscal.bkbMantemFiscal.dtoFiscal.numeroContrato}" 
                                                    styleClass="campoTexto"  maxlength="4" size="6"/>
                                            
                                            <strong><t:outputText value="/"/></strong>
                                            <t:inputText value="#{actMantemFiscal.bkbMantemFiscal.dtoFiscal.ano}"
                                                        styleClass="campoTexto" size="6"/> 
                                          <%--  <input type="text" name="ano" class="campoTexto"
                                                    maxlength="4" size="6"/> --%>
                                        </td>
                                    </tr>
                                    
                                      <tr>
                                        <td width="20%">
                                            <strong><t:outputText value="Tipo de instrumento:"/></strong>
                                        </td>
                                        <td width="80%">
                                           
                                             <t:selectOneMenu value=""
                                                            styleClass="combo">
                                                <f:selectItem itemValue="a" itemLabel=""/>
                                                <f:selectItem itemValue="ACORDO DE COOPERAÇÃO" itemLabel="ACORDO DE COOPERAÇÃO"/>
                                                <f:selectItem itemValue="APÓLICE DE SEGURO" itemLabel="APÓLICE DE SEGURO"/>
                                                <f:selectItem itemValue="CARTA - CONTRATO" itemLabel="CARTA - CONTRATO"/>
                                                <f:selectItem itemValue="CESSAO DE USO" itemLabel="CESSAO DE USO"/>
                                                <f:selectItem itemValue="COMODATO" itemLabel="COMODATO"/>
                                                <f:selectItem itemValue="CONTRATO EMERGENCIAL" itemLabel="CONTRATO EMERGENCIAL"/>
                                                <f:selectItem itemValue="CONVÊNIO" itemLabel="CONVÊNIO"/>
                                                <f:selectItem itemValue="CREDENCIMENTO" itemLabel="CONVÊNIO"/>
                                                <f:selectItem itemValue="NOTA DE EMPENHO" itemLabel="NOTA DE EMPENHO"/>
                                            </t:selectOneMenu>
                                           
                                        </td>
                                    </tr>
                                    
                                    <tr>
                                        <td>
                                            <strong>Unidade Gestora:</strong>
                                        </td>
                                        <td>
                                            <t:selectOneMenu value="#{actMantemFiscal.bkbMantemFiscal.dtoFiscal.unidadeGestora}"
                                                            styleClass="combo">
                                                <f:selectItem itemValue="a" itemLabel=""/>
                                                <f:selectItem itemValue="ADCOM" itemLabel="ADCOM"/>
                                                <f:selectItem itemValue="IGCE-10" itemLabel="IGCE-10"/>
                                                <f:selectItem itemValue="ISC" itemLabel="ISC"/>
                                                <f:selectItem itemValue="SECEX-1" itemLabel="SECEX-1"/>
                                                <f:selectItem itemValue="SECEX-2" itemLabel="SECEX-2"/>
                                                <f:selectItem itemValue="SECEX-3" itemLabel="SECEX-3"/>
                                                <f:selectItem itemValue="SECEX-4" itemLabel="SECEX-4"/>
                                                <f:selectItem itemValue="SECEX-5" itemLabel="SECEX-5"/>
                                                <f:selectItem itemValue="SECEX-6" itemLabel="SECEX-6"/>
                                                <f:selectItem itemValue="SECEX-AC" itemLabel="SECEX-AC"/>
                                                <f:selectItem itemValue="SECEX-AL" itemLabel="SECEX-AL"/>
                                                <f:selectItem itemValue="SECEX-AM" itemLabel="SECEX-AM"/>
                                                <f:selectItem itemValue="SECEX-AP" itemLabel="SECEX-AP"/>
                                                <f:selectItem itemValue="SECEX-BA" itemLabel="SECEX-BA"/>
                                                <f:selectItem itemValue="SECEX-CE" itemLabel="SECEX-CE"/>
                                                <f:selectItem itemValue="SECEX-ES" itemLabel="SECEX-ES"/>
                                                <f:selectItem itemValue="SECEX-GO" itemLabel="SECEX-GO"/>
                                                <f:selectItem itemValue="SECEX-MA" itemLabel="SECEX-MA"/>
                                                <f:selectItem itemValue="SECEX-MG" itemLabel="SECEX-MG"/>
                                                <f:selectItem itemValue="SECEX-MS" itemLabel="SECEX-MS"/>
                                                <f:selectItem itemValue="SECEX-MT" itemLabel="SECEX-MT"/>
                                                <f:selectItem itemValue="SECEX-PA" itemLabel="SECEX-PA"/>
                                                <f:selectItem itemValue="SECEX-PB" itemLabel="SECEX-PB"/>
                                                <f:selectItem itemValue="SECEX-PE" itemLabel="SECEX-PE"/>
                                                <f:selectItem itemValue="SECEX-PI" itemLabel="SECEX-PI"/>
                                                <f:selectItem itemValue="SECEX-PR" itemLabel="SECEX-PR"/>
                                                <f:selectItem itemValue="SECEX-RJ" itemLabel="SECEX-RJ"/>
                                                <f:selectItem itemValue="SECEX-RN" itemLabel="SECEX-RN"/>
                                                <f:selectItem itemValue="SECEX-RO" itemLabel="SECEX-RO"/>
                                                <f:selectItem itemValue="SECEX-RR" itemLabel="SECEX-RR"/>
                                                <f:selectItem itemValue="SECEX-RS" itemLabel="SECEX-RS"/>
                                                <f:selectItem itemValue="SECEX-SC" itemLabel="SECEX-SC"/>
                                                <f:selectItem itemValue="SECEX-SE" itemLabel="SECEX-SE"/>
                                                <f:selectItem itemValue="SECEX-SP" itemLabel="SECEX-SP"/>
                                                <f:selectItem itemValue="SECEX-TO" itemLabel="SECEX-TO"/>
                                                <f:selectItem itemValue="SECOB" itemLabel="SECOB"/>
                                                <f:selectItem itemValue="SECOI" itemLabel="SECOI"/>
                                                <f:selectItem itemValue="SEGEDAM" itemLabel="SEGEDAM"/>
                                                <f:selectItem itemValue="SEPLAN" itemLabel="SEPLAN"/>
                                                <f:selectItem itemValue="SETEC" itemLabel="SETEC"/>
                                            </t:selectOneMenu>
                                        
                                       
                                        </td>
                                    </tr>
                                 <tr>
                                        <td width="20%">
                                            <strong><t:outputText value="Fornecedor:"/></strong>
                                        </td>
                                        <td width="80%">
                                            <h:inputText value="" styleClass="campoTexto"  maxlength="4" size="50"/>
                                            
            
                                             <h:commandButton action=""
                                                              value="Localizar fornecedor"  styleClass="botoes" />
                                                            <h:messages showDetail="true"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="20%">
                                            <strong><t:outputText  value="Objeto (ou parte do objeto):"/></strong>
                                        </td>
                                        <td width="80%">
                                            <t:inputText value=""  
                                                    styleClass="campoTexto"  maxlength="4" size="100"/>
                                        
                                        </td>
                                    </tr>
                                    
                                           <tr>
                                        <td>
                                            <strong>Tipo de Licitação:</strong>
                                        </td>
                                        <td>
                                            <t:selectOneMenu value=""
                                                             styleClass="combo">
                                                <f:selectItem itemValue="a" itemLabel=""/>
                                                <f:selectItem itemValue="CONCORRÊNCIA" itemLabel="CONCORRÊNCIA"/>
                                                <f:selectItem itemValue="CONCURSO" itemLabel="CONCURSO"/>
                                                <f:selectItem itemValue="CONVITE" itemLabel="CONVITE"/>
                                                <f:selectItem itemValue="DISPENSA DE LICITAÇÃO" itemLabel="DISPENSA DE LICITAÇÃO"/>
                                                <f:selectItem itemValue="INEXIBILIDADE DE LICITAÇÃO" itemLabel="INEXIBILIDADE DE LICITAÇÃO"/>
                                                <f:selectItem itemValue="LEILÃO" itemLabel="LEILÃO"/>
                                                <f:selectItem itemValue="PREGÃO" itemLabel="PREGÃO"/>
                                                <f:selectItem itemValue="PREGÃO ELETRÔNICO" itemLabel="PREGÃO ELETRÔNICO"/>
                                                <f:selectItem itemValue="TOMADA DE PREÇOS" itemLabel="TOMADA DE PREÇOS"/>
                                                                                              
                                            </t:selectOneMenu>
                                        
                                       <h:commandButton action="detalha"
                                                         value="Pesquisar" styleClass="botoes"/>
                                                            <h:messages showDetail="true"/>
                                        </td>
                                    </tr>
                                   
                                </table>
                            </td>
                        </tr>
                    </table>
             
                 
            </h:form></body>
    </html>
</f:view>

Jsp2:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%> 
<f:view>
    <html>
        <head>
            <meta http-equiv="Conten,0t-Type"
                  content="text/html; charset=windows-1252"/>
            <title>Resultado da pesquisa de contratos</title>
            
            <link type="text/css" rel="stylesheet"
                  href="../../Shared/estilos/corporativoCBEX.css"/>
            <script type="text/javascript"
                    src="../../Shared/scripts/corporativo.js"></script>
                     <style type="text/css">
      a {
            border:0;
        }
      </style>
        </head>
         <body>
         
    <img id="imgIndicador" src="../../Shared/imagens/imgIconeEspera.gif" class="imagemCentro" alt="espera"
                style="display:none" height="100" width="100">
        <div id="telaEspera" style="display:none">
        </div>
    
        
  <h:outputText value="#{actMantemFiscal.menuSistema}" escape="false"/>
        
        <h:form>
                <h:panelGrid columns="2" styleClass="msgErro"
                             style="display:none" id="tabelaMsgErro"
                             title="msgErroFixa">
                    <h:graphicImage url="/Web/Shared/imagens/imgIconeErro.gif"
                                    height="20" width="20"/>
                    <h:outputText value="O preenchimento do(s) campo(s) está incorreto."/>
                </h:panelGrid>
                <%=tcu.util.formatHtml.FormatHtmlJsf.retornaErrosContextObject()%>
                <%=tcu.util.formatHtml.FormatHtmlJsf.retornaAlertasContextObject()%>
                <%=tcu.util.formatHtml.FormatHtmlJsf.retornaInfosContextObject()%>
               
                    <br></br>
                    <h1>
                        &nbsp;
                        <t:outputText value="Pesquisa Contrato"/>
                    </h1>
                    
                    <span class="style2">&nbsp;&nbsp;</span>
                     
                    <table width="100%" border="0" cellspacing="0"
                           cellpadding="0" class="tabelaSemLateral">
                        <tr>
                            <td>
                                <table width="100%" border="0" cellspacing="0"
                                       cellpadding="0" class="tabela">
                                    <tr>
                                        <th colspan="2">
                                            <div align="left">
                                                <t:outputText value=" Resultado da pesquisa"/>
                                            </div>
                                        </th>
                                    </tr>
                                                                                                        
                                    <tr>
                                        <td>
                 <t:dataTable var="fiscal"
                              value="#{actPesquisaContratos.bkbPesquisa.listaFiscais}"
                              rendered="#{actMantemFiscal.bkbMantemFiscal.listaFiscais!= null}"
                              styleClass="tabela">
                          
                    <t:column width=""  style="text-align:center;">
                        <f:facet name="header" >
                            <t:outputText value="Num. / Ano"
                                        style="text-align:center;"/>
                        </f:facet>
                           <f:verbatim>
                                      <input type="radio"
                                             value=""/>
                          </f:verbatim>
                      
                        <t:outputText value="#{fiscal.nome}"
                                    style="text-align:center;"/>
                                               
                                            </t:column>
                    <t:column width="" style="text-align:center;">
                        <f:facet name="header">
                            <t:outputText value="Tipo de instrumento"
                                        style="text-align:center;"/>
                        </f:facet>
                        <t:outputText value="#{fiscal.tipoDeInstrumento}"
                                    style="text-align:center;"/>
                    </t:column>
                    <t:column width="" style="text-align:center;">
                        <f:facet name="header">
                            <t:outputText value="Unidade gestora" style="text-align:center;"/>
                        </f:facet>
                        <t:outputText value="#{fiscal.unidadeGestora}"
                                    style="text-align:center;"/>
                    </t:column>
                    
                     <t:column width="" style="text-align:center;">
                        <f:facet name="header">
                            <t:outputText value="Fornecedor" style="text-align:center;"/>
                        </f:facet>
                        <t:outputText value="#{fiscal.fornecedor}"
                                    style="text-align:center;"/>
                    
                                            </t:column>
                                            
                           <t:column width="" style="text-align:center;">
                        <f:facet name="header">
                            <t:outputText value="Possui termo aditivo?" style="text-align:center;"/>
                        </f:facet>
                        <t:outputText value="#{fiscal.possuiTermoAditivo}"
                                    style="text-align:center;"/>
                    
                                            </t:column>
                </t:dataTable>
                                        </td>
                                    </tr>
                                    
                                    <tr>
                                        
                                        <td width="80%">  
                                        <br />
                                   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;         <h:commandButton action="#{actMantemFiscal.pesquisar}"
                                                                         value="Pesquisar" styleClass="botoes"/>
                                                            <h:messages showDetail="true"/>
                                       
                                        </td>
                                    </tr>
                                     
                                </table>
                            </td>
                        </tr>
                    </table>
             
                 
            </h:form></body>
    </html>
</f:view>

FacesConfig.xml

<?xml version='1.0' encoding='UTF-8'?>


<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<!-- =========== FULL CONFIGURATION FILE ================================== -->

<faces-config>
    <navigation-rule>
        <from-view-id>/Web/Contrata/mantemFiscal/mantemFiscal.jsp</from-view-id>
        <navigation-case>
            <from-outcome>detalha</from-outcome>
            <to-view-id>/Web/Contrata/mantemFiscal/resultadoPesquisaContratos.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
    <managed-bean>
        <managed-bean-name>actMantemFiscal</managed-bean-name>
        <managed-bean-class>tcu.contrata.apresentacao.mantemFiscalContrato.ActMantemFiscal</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <from-view-id>/Web/Contrata/mantemFiscal/historicoFiscais.jsp</from-view-id>
        <navigation-case>
            <from-outcome>atualizarFiscal</from-outcome>
            <to-view-id>/Web/Contrata/mantemFiscal/atualizarFiscal.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>adicionarFiscal</from-outcome>
            <to-view-id>/Web/Contrata/mantemFiscal/adicionarFiscal.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
    <managed-bean>
        <managed-bean-name>actAtualizaFiscal</managed-bean-name>
        <managed-bean-class>tcu.contrata.apresentacao.mantemFiscalContrato.ActAtualizaFiscal</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <from-view-id>/Web/Contrata/mantemFiscal/atualizarFiscal.jsp</from-view-id>
        <navigation-case>
            <from-outcome>fiscalAtualizado</from-outcome>
            <to-view-id>/Web/Contrata/mantemFiscal/historicoFiscais.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>voltar</from-outcome>
            <to-view-id>/Web/Contrata/mantemFiscal/historicoFiscais.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
    <navigation-rule>
        <from-view-id>/Web/Contrata/mantemFiscal/adicionarFiscal.jsp</from-view-id>
        <navigation-case>
            <from-outcome>Adicionar</from-outcome>
            <to-view-id>/Web/Contrata/mantemFiscal/historicoFiscais.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>voltar</from-outcome>
            <to-view-id>/Web/Contrata/mantemFiscal/historicoFiscais.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
    <managed-bean>
        <managed-bean-name>pessoa</managed-bean-name>
        <managed-bean-class>tcu.contrata.apresentacao.mantemFiscalContrato.Pessoa</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <managed-bean>
        <managed-bean-name>actPesquisaContratos</managed-bean-name>
        <managed-bean-class>tcu.contrata.apresentacao.mantemFiscalContrato.ActPesquisaContrato</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <from-view-id>/Web/Contrata/mantemFiscal/resultadoPesquisaContratos.jsp</from-view-id>
        <navigation-case>
            <from-outcome>historico</from-outcome>
            <to-view-id>/Web/Contrata/mantemFiscal/historicoFiscais.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
</faces-config>
thiago.limma

Não dá nenhuma exception. Apenas um refresh na página.

vanilton.coelho

cadê o managed bean e qual botao que executa a action que deverá redirecionar para outra página ???

thiago.limma
#  <h:commandButton action="detalha"  
#                                                          value="Pesquisar" styleClass="botoes"/>  
#                                                             <h:messages showDetail="true"/>

Esse é o botão. A navegação é feita através do faces config.xml, através do action "detalha".

vanilton.coelho

cara, nesse atributo action ai do commandButtom vc deve definir qual metodo será chamado de seu manageb bean, metodo este que retorna String e lá dentro do metodo, vc retornaria a String que está sendo mapeada dentro do faces-config. sacou???

até onde sei não sabia que vc podia definir a String direto ali no action nao.

thiago.limma

Eu já fiz isso aqui em outro sistema e dá certo sim… Na dúvida, criei um método retornando a string, mas também não funcionou.

thiago.limma

Ninguém?? =/

Criado 11 de setembro de 2008
Ultima resposta 12 de set. de 2008
Respostas 9
Participantes 4