0

I have 3 jsf pages : welcome page : index.xhtml second page : displayall.xhmtl containing a commandlink to the third page : login_jsf.xhtml

The problem is when I press navigator return button it's redirect to the welcome page instead of displayall.xhtml

here is the tag I use to redirect :

   <p:commandLink id="login" action="login_jsf?faces-redirect=true" style="margin-right:20px">
                <h:outputText value="Se connecter" />
            </p:commandLink>

my web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>exemple_jpa</display-name>
  <welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
  </welcome-file-list>
  <context-param>
    <param-name>com.sun.faces.numberOfViewsInSession</param-name>
    <param-value>5</param-value>
  </context-param>
  <context-param>
    <param-name>com.sun.faces.serializeServerState</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>primefaces.CLIENT_SIDE_VALIDATION</param-name>
    <param-value>true</param-value>
  </context-param>
  <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>


</web-app>
DarkSide
  • 25
  • 1
  • 9
  • 1
    How about using `login?faces-redirect=true` (without `_jsf`). See also http://stackoverflow.com/questions/15521451/how-to-navigate-in-jsf-how-to-make-url-reflect-current-page-and-not-previous-o – Jasper de Vries May 01 '17 at 18:41

1 Answers1

1

Add a navigation rule to your faces-config.xml (notice the "redirect" tag):

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

or make a navigation handler bean and call its related method from the commandLink:

@Named
@RequestScoped
public class NavigationHandler implements Serializable {
   public String moveToLoginPage() {
      return "login?faces-redirect=true";
   }
}

and then:

<p:commandLink id="login" action="#{navigationHandler.moveToLoginPage}"> 
          <h:outputText value="Se connecter" />
</p:commandLink>
patateskafa
  • 149
  • 2
  • 12