Jsf 如何在托管bean中导航到另一个页面?
我正在尝试使用commandbutton转发托管bean中的页面:Jsf 如何在托管bean中导航到另一个页面?,jsf,redirect,navigation,forward,Jsf,Redirect,Navigation,Forward,我正在尝试使用commandbutton转发托管bean中的页面: <h:commandButton action="#{bean.action}" value="Go to another page" /> 重定向页面,而不是转发。我看到了与此类似的问题,并尝试了给定的解决方案: public void action() throws IOException { FacesContext.getCurrentInstance().getExternalContext().
<h:commandButton action="#{bean.action}" value="Go to another page" />
重定向页面,而不是转发。我看到了与此类似的问题,并尝试了给定的解决方案:
public void action() throws IOException {
FacesContext.getCurrentInstance().getExternalContext().dispatch("another.xhtml");
}
但我得到了以下错误:
Index: 0, Size: 0
那么,如何从托管bean转发到页面呢?只需将其作为操作方法返回值返回即可
public String action() {
return "another.xhtml";
}
如果您除了导航之外没有做任何其他事情,那么您也可以直接将字符串结果放入action
属性中
<h:commandButton action="another.xhtml" value="Go to another page" />
然而,这反过来又是一种相当糟糕的做法。您不应该执行普通页到页导航的POST请求。只需使用一个简单的按钮或链接:
<h:button outcome="another.xhtml" value="Go to another page" />
另见:
rendered=“#{notempty bean.results}”
在同一视图中有条件地显示结果吗?另请参见第二个“另请参见”链接以获取建议。
<h:button outcome="another.xhtml" value="Go to another page" />