3
votes

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

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

1
The issue is oncomplete is defined before the ajax event fired. So the value will be the older one only. i.e. on each ajax request the javascript will be called with the older value. So I suggest you to take a hidden component to get the new value. - Jitesh
Jitesh, Tank you for your answer! - Makko

1 Answers

2
votes

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.

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