我如何从h:commandButton导航到绝对路径

时间:2013-02-20 12:24:37

标签: jsf-2 richfaces commandbutton

我有这样的事情:

<h:commandButton value="test" action="#{bean.action}"/>

一旦评估了action方法,我想导航(仅在某些情况下)为绝对URL。

我知道如果“bean.action”返回一个与上下文中的有效路径相对应的相对路径,它将会去那里,但我不希望这样。

我想评估操作返回,如果一切正常,请导航到像“www.anypage.com”这样的绝对网址,例如

<a href="www.anypage.com">test</a>

但取决于行动回报并保持jsf2优势。

有什么想法吗?很多

1 个答案:

答案 0 :(得分:2)

很简单,只需在您的操作方法中使用ExternalContext.redirect()

public String action() {
    doYourProcessing();
    if(/*some condition*/) {
        FacesContext.getCurrentInstance().getExternalContext().redirect(/*absolute path*/);
    } else {
        //return a navigation case outcome or null for a postback
    }
}