ExternalContext.dispatch() not working

≯℡__Kan透↙ 提交于 2019-12-18 08:49:23

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/14163457/externalcontext-dispatch-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!