ExternalContext.dispatch() 不起作用 [英] ExternalContext.dispatch() not working

查看:20
本文介绍了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.

推荐答案

ExternalContext#dispatch() 不支持ajax请求.它会导致 JSF 呈现 JavaScript ajax 引擎无法理解的给定资源的 HTML 输出.ajax 请求必须返回一个 JavaScript ajax 引擎可以理解的特殊 XML 响应.

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.

ExternalContext#redirect() 支持ajax请求.它将自动返回一个特殊的 XML 响应,指示 JavaScript ajax 引擎对给定的 URL 调用 window.location 调用(您可以在 这个答案).

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

您有两个选择:

  1. 使其成为非 ajax 请求.
  2. 执行普通的 JSF 导航.

发出非 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天全站免登陆