JSF Redirect

1

I want to redirect the main page to login page so I configured faces-config.xml together with the main page below my code for you to see

Code

faces-config.xml

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

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee  http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">


<navigation-rule>

    <navigation-case>
        <from-outcome>login</from-outcome>
        <to-view-id>/Login.xhtml</to-view-id>
      <redirect/>
    </navigation-case>
</navigation-rule>

<managed-bean>
    <managed-bean-name>usuario</managed-bean-name>
    <managed-bean-class>MB.Usuario</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

My Home Page.

  <f:view>
<h:head>
    <title>Facelet Title</title>


    <!--header-middle<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />    <h:outputStylesheet name="./css/main.css"/>
    <h:outputStylesheet name="./css/responsive.css"/>
    <h:outputStylesheet library="css" name="main.css"/>-->


    <title>Facelets Template</title>

    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/cssPrimeFaces/default.css" />
        <link type="text/css" rel="stylesheet" href="#{request.contextPath}/cssPrimeFaces/principal.css" />

        <style type="text/css">
               .ui-layout-north {
                      z-index:20 !important;
                     overflow:visible !important;;
                }

              .ui-layout-north .ui-layout-unit-content {
                    overflow:visible !important;
               }
        </style>


</h:head>
<h:body>
    <h:form>

     <h:panelGroup layout="block" id="header">
        <ui:insert name="top"><!--não pode ter dois ui na mesma tag, ui serve como container-->
     <h:panelGroup id="header_top">
         <h:panelGroup layout="block" styleClass="container"> <!--painel gropu block, como div, styleClass, classe-->  
   <b:column col-sm="6">
            <h:panelGroup layout="block" styleClass="contactinfo">
          <ul class="nav nav-pills">
         <li><i class="fa fa-phone"></i> +2 95 01 88 821</li>
        <li><i class="fa fa-envelope"></i> [email protected]</li>    
        </ul>

        </h:panelGroup>  
     </b:column> 

              <b:column col-sm="6">
                     <h:panelGroup layout="block" styleClass="docial-icons pull-right">
            <ul class="nav navbar-nav">
    <li><i class="fa fa-facebook" action="" ></i></li>
    <li><i class="fa fa-twitter" action=""></i></li>
    <li><i class="fa fa-linkedin" action=""></i></li>
    <li><i class="fa fa-dribbble" action=""></i></li>
    <li><i class="fa fa-google-plus" action=""></i></li>
    </ul>
                         </h:panelGroup>
                 </b:column>
                 </h:panelGroup>

         </h:panelGroup> 
            </ui:insert>


         <h:panelGroup layout="block" styleClass="header-middle"><!--header-middle-->
                <h:panelGroup layout="block" styleClass="container">
         <b:row>
             <b:column col-sm="4">

                 <h:panelGroup layout="block" styleClass="logo_pull_left">

                     <h:commandLink action="index.xhtml">
                   <h:graphicImage library="imagens" name="winnerlogo.png"/> 
                     </h:commandLink>

              </h:panelGroup>

             </b:column>


              <b:column col-sm="8">
                 <h:panelGroup layout="block" styleClass="shop-menu pull-right">

        <ul class="nav navbar-nav">
                        <li><i class="fa fa-user"></i><h:commandLink action="#{navegacao.redirecionarConta()}" value="Minha Conta" /></li>
                        <li><i class="fa fa-shopping-cart"></i><h:commandLink action="#{navegacao.redirecionarCarrinho()}" value="Carrinho de compras" /></li>

                        <li><i class="fa fa-lock"></i><h:commandLink action="login" value="Login"/></li>
        </ul>

        </h:panelGroup>

             </b:column>

         </b:row>

                </h:panelGroup>
</h:panelGroup>
         </h:body></h:form>
    
asked by anonymous 20.06.2017 / 20:32

2 answers

1

You could use web.xml for this

<welcome-file-list> <welcome-file>/login.xhtml</welcome-file> </welcome-file-list>

    
22.06.2017 / 22:39
0

I confess that I have never done the system redirects I worked on by mapping them to faces-config.xml .

I've always done right through action .

To do with action simply return the page name to forward or return the page name + ?faces-redirect=true to do redirection . p>

For example:

View:

<h:commandLink action="#{seuManagedBean.redirecionaLogin}" value="Login"/>

ManagedBean:

public class SeuManagedBean {

    public String redirecionaLogin() {
        return "login";
        //ou
        //return "login?faces-redirect=true";
    }
}

Note that it is not necessary to tell the page extension (.xhtml, .jsf, or any other extension).

    
23.06.2017 / 19:04