为什么NavigationHandler.handleNavigation()不转发查看ID?

时间:2010-04-02 21:59:21

标签: jsf

在“RESTORE_VIEW”阶段运行的阶段侦听器类内部,我有一些代码如下:

public void afterPhase(PhaseEvent event) {
  FacesContext fc = event.getFacesContext();
  NavigationHandler nh = fc.getApplication().getNavigationHandler();
  nh.handleNavigation(fc, null, "/a/specific/path/to/a/resource.jspx");
}

导航到新网址不起作用。发出的请求只会收到导航到的原始JSPX的响应。

这样的代码工作正常:

public void afterPhase(PhaseEvent event) {
  FacesContext fc = event.getFacesContext();
  NavigationHandler nh = fc.getApplication().getNavigationHandler();
  nh.handleNavigation(fc, null, "OUTCOME_DEFINED_IN_FACES_CONFIG_XML");
}

此外,第一个代码段将与IceFaces Faces提供程序一起使用,但不是Sun JSF 1.2,这是我需要使用的。我可以做些什么来修复代码,以便可以转发到特定的URL?

2 个答案:

答案 0 :(得分:3)

请改用ExternalContext#dispatch()

或者,如果它应该是重定向,请使用ExternalContext#redirect()

它在IceFaces中有效必须是bug或impl特定的“功能”。这不是NavigationHandler API合约定义的内容。

答案 1 :(得分:1)

我好像找到了答案。以下代码对我来说很好:

public void afterPhase(PhaseEvent event) {
  FacesContext fc = event.getFacesContext();
  NavigationHandler nh = fc.getApplication().getNavigationHandler();
  fc.getViewRoot().setViewId("/a/specific/path/to/a/resource.jspx");
}