javascript - Ajax 更新后 JSF 调用 javascript 函数

标签 javascript ajax jsf

我有 jsf 代码,在 javascript 单击后调用隐藏按钮单击功能,执行 ajax 请求并刷新页面。但是我想在 ajax 返回新值时调用另一个 javascript 函数。这是我的代码

  <h:panelGrid styleClass="float-left" columns="2">                                                
                            <h:outputText value="Хранилище ключей: "  />
                            <h:panelGroup>
                                <p:inputText  value="#{SessionBean.getCurrentLocaleName(SessionBean.userProfileController.keySettingsForm.storage)}" onclick="$('#selectStorageB').click();" onchange="" readonly="true" style="cursor: text; width: 275px;" />
                                <p:commandButton id="selectStorageB" style="display: none;"
                                                 actionListener="#{SessionBean.storageController.selectStorageForm.openSelectStorageDialog}">
                                    <p:ajax event="dialogReturn" update=":indexForm" process=":indexForm" immediate="true"
                                            listener="#{SessionBean.userProfileController.keySettingsForm.onStorageChosen}"  oncomplete="chooseStoragePath(#{SessionBean.userProfileController.keySettingsForm.storage.alias})" />
                                </p:commandButton>
                                <p:commandButton icon="ui-icon-cancel" immediate="true" style="width: 18px; white-space: pre-wrap; margin-left: 5px" 
                                                 actionListener="#{SessionBean.userProfileController.keySettingsForm.resetSigningStorageName()}" update=":indexForm">
                                </p:commandButton>
                            </h:panelGroup>
                        </h:panelGrid>

我的问题是 javascript 函数看不到新值。

最佳答案

由于您使用的是 Primefaces,因此您可以使用 Primefaces 在您的 ManagedBean 本身的操作方法中调用 Javascript 函数 RequestContextexecute方法。

String script = "chooseStoragePath('"+PATH_VAR+"')";
RequestContext.getCurrentInstance().execute(script);

关于javascript - Ajax 更新后 JSF 调用 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28666848/

相关文章:

javascript - 在 while 循环中显示/隐藏函数

c# - ajax 发送 FormData c# WebMethod

jsf - 如何更改primefaces中的菜单按钮图标?

javascript - 使用 AngularJS 对 $http 请求实现延迟 ($timeout)

javascript - 删除不适用于 NodeJs 中的 javascript 对象

javascript - 需要在javascript中保留空格

来自 Chrome 扩展的 ajax 已处理,但收到 responseText =""和 status=0

javascript - 以 Angular 向谷歌表单提交数据时出现 CORS 问题

jsf - 为什么 WildFly 10 + JSF 2.3 不能与 Omnifaces 2.6.1 一起使用?

java - 如何使用Primefaces在Java中查找数据源(dataTable)?