有没有办法将页面从 Java 方法重定向到其他页面?
我只能使用以下方式转发它:
FacesContext.getCurrentInstance().getExternalContext().dispatch("/foo.xhtml");
或使用导航规则faces-config.xml
。
你有什么想法?
有没有办法将页面从 Java 方法重定向到其他页面?
我只能使用以下方式转发它:
FacesContext.getCurrentInstance().getExternalContext().dispatch("/foo.xhtml");
或使用导航规则faces-config.xml
。
你有什么想法?
不知道你在追求什么,但ExternalContext#dispatch()
它只做转发,而不是重定向。你想ExternalContext#redirect()
改用。
externalContext.redirect("foo.xhtml");
甚至是外部的(这在调度中是不可能的)
externalContext.redirect("http://stackoverflow.com");
您通常希望在 bean 的 action 方法中执行此操作。
由于您在评论中提到了 JavaScript,因此您可以使用 JS 进行重定向:
window.location = "foo.xhtml";
// Or
window.location = "http://stackoverflow.com";
FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), null, "page.xhtml");
效果也一样。
请尝试调用以下静态函数:
String url = "/meta/default/inbox"; // Your URL here
FacesContext.getCurrentInstance().getExternalContext().redirect(url);