Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JSF中使用导航_Jsf_Jsf 2 - Fatal编程技术网

在JSF中使用导航

在JSF中使用导航,jsf,jsf-2,Jsf,Jsf 2,框架:JSF2.0。 public static void redirectUsingNavigation(String from, String outCome) { FacesContext facesContext = FacesContext.getCurrentInstance(); facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, from, outC

框架:JSF2.0。

public static void redirectUsingNavigation(String from, String outCome) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, from, outCome);
}
我的问题:我有一个名为login.xhtml的页面。每当有人查看该页面时,它就会调用一个过滤器,称为身份验证过滤器。过滤器将检查,如果用户已经登录,它将根据用户的角色重定向到默认值(例如:Admin将转到“Admin/Admin.xhtml”,student将重定向到“user/user.xhtml”)

我的解决方案:使用JSF导航

我的配置:

faces config.xml

我的问题:

public static void redirectUsingNavigation(String from, String outCome) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, from, outCome);
}
  • 当我运行重定向UsingNavigation(“*”,“AD”)重定向UsingNavigation(null,“AD”)时,它不会将我重定向到admin.xhtml(我仍在登录.xhtml)。如何解决这个问题
  • 在这个问题上,有任何框架支持我吗

  • 该代码根本没有重定向。它只是在转发请求。它只是对不同的目标页面使用相同的请求对象)。实际重定向指示浏览器在给定的
    位置
    标题上发送新请求。您可以在浏览器地址栏中看到此更改

    您需要向结果中添加
    faces redirect=true
    参数来触发重定向(如果您使用隐式导航而不是冗长的导航案例,这尤其有用):

    如果您希望导航案例始终发生,请将其添加到导航案例中:

    
    *
    公元
    /admin/admin.xhtml
    美国
    /user/user.xhtml
    
    最后但并非最不重要的一点是,您需要确保在提交响应之前调用
    handleNavigation()
    ,否则它将根本无法工作,并且服务器日志中会充斥
    IllegalStateException:response ready committed
    错误。您可以使用
    在提交响应之前调用bean操作

    另见:
    navigationHandler.handleNavigation(facesContext, from, outCome + "?faces-redirect=true")