function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cmoynihancmoynihan 

Apex method variable lost when actionFunction calls Javascript using oncomplete

I have an actionFunction defined that calls an Apex function called register() that does some work with contacts. Depending on the result of the function, it sets a message variable with some results.

 

When I call my actionFunction normally I see the message displayed on my page:

 

 

<apex:actionFunction name="register" action="{!register}" rendered="true" immediate="false"  />
<p>Message: {!message}</p>

 

 

 

 When I try to call some Javascript (a function which displays an jQuery Tools overlay, with the message variable as text) using the oncomplete attribute, my message is lost.

 

<apex:actionFunction name="register" action="{!register}" rendered="true" immediate="false" oncomplete="showMsg()" />
 
<apex:outputPanel layout="block" styleClass="simple_overlay" id="regMessage">
  <p>Message: {!message}!</p>
</apex:outputPanel>

 

I am guessing this is because somehow once the actionFunction is complete, the method variables get cleared out. If that's the case, can I somehow return the message from the Apex method so that I can use it on my page?

vhanson222vhanson222

try adding Rerender="regMessage" to the action Function.  The re-render should cause the new field value to be displayed.

LakshmanLakshman

Hi

 

Here is my suggestion:

 

Instead of using oncomplete function, pass a parameter like completed=yes to in your PageReference while returning from your register method. After this read this parameter in your js and then show your desired message.

I have also faced this issue recently, so I did this work aroung to retain my data.

 

Let me know if this works.

 

-Lakshman