从Java Bean重定向JSF页面 [英] JSF page redirecting from java bean
本文介绍了从Java Bean重定向JSF页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以从Java方法将页面重定向到其他页面吗?
Is there some way how to redirect page to other page from Java method?
我只能通过以下方式转发:
FacesContext.getCurrentInstance().getExternalContext().dispatch("/foo.xhtml");
或使用faces-config.xml
的导航规则.
您有什么想法吗?
推荐答案
不确定您要执行的操作,但是ExternalContext#dispatch()
仅执行转发操作,而不执行重定向操作.您想使用
Not sure what you're after, but the ExternalContext#dispatch()
does only a forward, not a redirect. You'd like to use ExternalContext#redirect()
instead.
externalContext.redirect("foo.xhtml");
甚至是外部的(分派是不可能的)
or even external (which is not possible with dispatch)
externalContext.redirect("http://stackoverflow.com");
您通常希望在bean的action方法中执行此操作.
You'd normally like to do this in bean's action method.
由于您在注释中提到了JavaScript,因此可以使用JS进行重定向:
Since you mentioned JavaScript in the comments, here's how you could redirect using JS:
window.location = "foo.xhtml";
// Or
window.location = "http://stackoverflow.com";
这篇关于从Java Bean重定向JSF页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文