Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is NavigationHandler.handleNavigation() not forwarding to view ID?

Tags:

jsf

Inside of a phase listener class that runs during the "RESTORE_VIEW" phase, I have some code like this:

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");
}

Navigation to the new URL doesn't work here. The request made will just receive a response from the original JSPX that was navigated to.

Code like this works fine:

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

Also the first snippet will work with an IceFaces Faces provider, but not Sun JSF 1.2 which is what I need to use. Is there something I can do to fix the code so it is possible to forward to specific URLs?

like image 423
Erik Hermansen Avatar asked Nov 24 '25 12:11

Erik Hermansen


1 Answers

Use ExternalContext#dispatch() instead.

Or, if it is supposed to be a redirect, use ExternalContext#redirect().

That it works in IceFaces must be a bug or impl-specific "feature". This is namely not what the NavigationHandler API contract definies.

like image 110
BalusC Avatar answered Nov 27 '25 16:11

BalusC