ExternalContext.dispatch()无法正常工作 [英] ExternalContext.dispatch() not working

查看:137
本文介绍了ExternalContext.dispatch()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在p:ajax调用中,侦听器调用包含

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).

您有2个选择:

  1. 将其设为非ajax请求.
  2. 执行常规的JSF导航.

发出非ajax请求很可能不是<p:ajax>的选项.在这种情况下,执行常规导航实际上是您唯一的选择.

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

在ajax请求的情况下,它将自动强制 render="@all" 中包含新内容.

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

这篇关于ExternalContext.dispatch()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆