gpt4 book ai didi

java - PrimeFaces v3.5 : Dialog is not shown using RequestContext on non-Ajax calls

转载 作者:行者123 更新时间:2023-11-30 04:29:20 24 4
gpt4 key购买 nike

在用户指南中,声明 RequestContext 将适用于 Ajax 和非 Ajax 调用。然而,用户指南中的所有示例都使用 Ajax,在我的例子中,它不适用于非 Ajax 调用。

以下是测试页面:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Test page</title>
</h:head>
<h:body>
<h:form >

<p:commandButton ajax="false" value="Non-Ajax" actionListener="#{mrBean.show}" />

<p:commandButton value="Ajax" actionListener="#{mrBean.show}" />

</h:form>

<p:dialog modal="true" id="statusDialog" widgetVar="statusDlg" closable="false" >
<h:outputText value="Helllooo" />
</p:dialog>
</h:body>
</html>

这是托管 bean:

@ManagedBean
@RequestScoped
public class MrBean {

public void show() {
System.out.println("SHOW DIALOG");
RequestContext context = RequestContext.getCurrentInstance();
context.execute("statusDlg.show();");
}

}

如果我单击Ajax 按钮,对话框将正确显示。然而,Non-Ajax 按钮没有执行任何操作。在这两种情况下,SHOW DIALOG 消息都会打印在控制台上。

如果您能告诉我如何解决这个问题,我将非常感激:)。

最诚挚的问候,

詹姆斯·特兰

最佳答案

我一定会让你失望,但是非 AJAX 请求中的 RequestContext 是可用的,但唯一有用的函数是带有 boolean 返回值的 isAjaxRequest() 。在文档和 API 引用中,您可以看到对于所有其他方法,都被告知它们用于 AJAX 请求。同样对于 execute() 方法:

Execute a javascript after current ajax request is completed.

过去,RequestContext 根本不可用,现在它仅可用于将来可能用于非 AJAX 请求的情况。另请参阅this issue

关于java - PrimeFaces v3.5 : Dialog is not shown using RequestContext on non-Ajax calls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15039392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com