Redirecting JSF pages

Asked

Viewed 580 times

1

I’m looking to redirect the main page to login page so I set the 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>

2 answers

1

You could use the web.xml for that reason

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

0

I confess I never rerouted the systems I worked on by mapping them through faces-config.xml.

I’ve always done right by action.

To do for action just return the page name to do the forwarding or return the page name + ?faces-redirect=true to do the redirecting.

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 inform the Language extension (.xhtml, . jsf or any other extension).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.