jsf返回欢迎页面而不是上一页

时间:2017-04-30 09:16:16

标签: jsf primefaces jsf-2

我有3个jsf页面: 欢迎页面:index.xhtml 第二页:displayall.xhmtl包含第三页的命令链接:login_jsf.xhtml

问题是,当我按导航器返回按钮时,它会重定向到欢迎页面,而不是displayall.xhtml

这是我用来重定向的标签:

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

我的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>

1 个答案:

答案 0 :(得分:1)

faces-config.xml 添加导航规则(注意“重定向”标记):

<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>

或创建导航处理程序bean并从commandLink调用其相关方法:

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

然后:

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