我有 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 函数 RequestContext的 execute方法。
String script = "chooseStoragePath('"+PATH_VAR+"')";
RequestContext.getCurrentInstance().execute(script);
关于javascript - Ajax 更新后 JSF 调用 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28666848/