如何以编程方式执行JSF内部页面转发?

Raj*_*pta 7 jsf forward jsf-2

在某些条件下(如果发生异常时),如何在托管bean中以编程方式转发JSF内部页面?转发到其他页面时我不想更改URL.

现在我使用它以编程方式重定向到另一个页面,但这会更改URL.

FacesContext.getCurrentInstance().getExternalContext().redirect();
Run Code Online (Sandbox Code Playgroud)

Mr.*_*mes 6

试试这个:

public void forward(){
    String uri = "destination.xhtml";
    FacesContext.getCurrentInstance().getExternalContext().dispatch(uri);
}
Run Code Online (Sandbox Code Playgroud)

  • 这是Servlet重定向,使用JSF导航处理程序使用:FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(),null,"YOUR_NAVIGATION_CASE_DEFINED_IN_FACES_CONFIG"); (3认同)