0

I have server-side coundown counter. When it == 0, method should execute ExternalContext#dispatch(), but it didn't do it. Method ExternalContext#redirect() works correctly on this place.

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

I tried a few ways of the spelling url(result,result.xhtml,\result.xhtml etc.) with the same result.

burnmyheaven
  • 137
  • 2
  • 15

1 Answers1

2

This is not the right way to let JSF navigate to a different view.

If you're inside an action method, you should be returning it as string instead.

public String submit() {
    // ...

    return "result.xhtml";
}

Or if you're not inside an action method and couldn't change it to a fullworthy action method for some unclear reason, then use NavigationHandler#handleNavigation() instead.

FacesContext context = FacesContext.getCurrentInstance();
context.getApplication().getNavigationHandler().handleNavigation(context, null, "result.xhtml");
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you for your advice, but it works like `ExternalContext#redirect()` in my case. I need "forced" navigation, which would simulate pressing `` or working action method. – burnmyheaven Feb 27 '13 at 12:09
  • 1
    No, it doesn't perform a redirect at all. It performs a forward. It works only like `ExternalContext#redirect()` if you use `result.xhtml?faces-redirect=true` as outcome. – BalusC Feb 27 '13 at 12:17