问题描述:

On p:ajax call,listener invokes method which contains

 FacesContext.getCurrentInstance().getExternalContext().dispatch("/uri.jsf");

doesn't work. Ive set a break point on the line and it remains at the same point on execution.It doesn't move forward, I ve got to restart server to run the application again.

 FacesContext.getCurrentInstance().getExternalContext().redirect("/uri.jsf");

redirection works perfectly fine. But i want page forward which is dispatch to navigate to another page.

网友答案:

The ExternalContext#dispatch() does not support ajax requests. It causes JSF to render the HTML output of the given resource which can't be understood by the JavaScript ajax engine. The ajax request has to return a special XML response which can be understood by the JavaScript ajax engine.

The ExternalContext#redirect() supports ajax requests. It will automatically return a special XML response instructing the JavaScript ajax engine to invoke a window.location call on the given URL (you can find an XML example in this answer).

You have 2 options:

  1. Make it a non-ajax request.
  2. Perform a normal JSF navigation.

Making a non-ajax request is most likely not an option for <p:ajax>. In that case, performing a normal navigation is really your only option.

FacesContext context = FacesContext.getCurrentInstance();
context.getApplication().getNavigationHandler().handleNavigation(context, null, "/uri.jsf");

It will in case of ajax requests automatically force an render="@all" with the new content.

相关阅读:
Top