39

Javaメソッドからページを他のページにリダイレクトする方法はありますか?

私はそれを使用して転送することしかできません:

FacesContext.getCurrentInstance().getExternalContext().dispatch("/foo.xhtml");

または のナビゲーション ルールを使用しfaces-config.xmlます。

あなたはなにか考えはありますか?

4

3 に答える 3

69

何を求めているのかわかりませんがExternalContext#dispatch()、リダイレクトではなく転送のみを行います。ExternalContext#redirect()代わりに使用したいと思います。

externalContext.redirect("foo.xhtml");

または外部(ディスパッチでは不可能)

externalContext.redirect("http://stackoverflow.com");

通常は、Bean のアクション メソッドでこれを行います。


コメントで JavaScript について言及したので、JS を使用してリダイレクトする方法は次のとおりです。

window.location = "foo.xhtml";
// Or
window.location = "http://stackoverflow.com";
于 2011-05-10T21:42:10.783 に答える
2
FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), null, "page.xhtml");

Works just as well.

于 2014-06-19T10:42:34.030 に答える