JSF在Ajax更新后调用javascript函数

时间:2022-10-08 09:02:03

I have jsf code which after javascript click calls hidden button click function, that performs ajax request and refresh the page. But I want call another javascript function when ajax returns new values. Here is my code

我有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>

My problem is javascript function does not see new values.

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

1 个解决方案

#1


2  

Since you are using Primefaces you could call the Javascript function from your Action Method at your ManagedBean itself using Primefaces RequestContext's execute method.

由于您使用的是Primefaces,因此您可以使用Primefaces RequestContext的execute方法在ManagedBean本身的Action Method中调用Javascript函数。

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

#1


2  

Since you are using Primefaces you could call the Javascript function from your Action Method at your ManagedBean itself using Primefaces RequestContext's execute method.

由于您使用的是Primefaces,因此您可以使用Primefaces RequestContext的execute方法在ManagedBean本身的Action Method中调用Javascript函数。

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