ExternalContext#dispatch()不起作用

时间:2013-02-27 09:48:50

标签: jsf

我有服务器端coundown计数器。当它== 0时,方法应该执行ExternalContext#dispatch(),但它没有这样做。方法ExternalContext#redirect()在这个地方正常工作。

....
        }else{
        try {
            FacesContext.getCurrentInstance().getExternalContext().dispatch("result.xhtml");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
....

我尝试了几种拼写网址(result,result.xhtml,\result.xhtml等),结果相同。

1 个答案:

答案 0 :(得分:2)

这不是让JSF导航到不同视图的正确方法。

如果你在一个动作方法中,你应该把它作为字符串返回。

public String submit() {
    // ...

    return "result.xhtml";
}

或者,如果您不在某个操作方法中,并且由于某些不明原因而无法将其更改为完整的操作方法,请改用NavigationHandler#handleNavigation()

FacesContext context = FacesContext.getCurrentInstance();
context.getApplication().getNavigationHandler().handleNavigation(context, null, "result.xhtml");
相关问题