+ Start a Discussion
Ken KoellnerKen Koellner 

rerender doesn't work on actionFunction when actionFunction called from commandButton

function doItWrapper() {
  // alert("in doItWrapper()");
<apex:actionFunction name="doItFunc" action="{!doItInner}" rerender="resultPanel"/>

Change Me: <input type="text" id="fname" onchange="doItWrapper()"/>
<apex:commandButton value="Do It Wrapper" onClick="doItWrapper();" />


Relavent portion of code above.


I find that when the commandButton is pressed, the doItWrapper() function is execute which in turns executes the doItFunc actionFunction.  The actionFunction does call the server.  But, the rerender doesn't happen,  resultPanel is an outputPanel and its contents do not change.


When I change the value in the field labelled "Change me", it works fine.  doItWrapper() is called; the actionFunction is called which calls the server; and then the panel is rerendered just fine.


Anyone know why the rerender doesn't work when the script is invoked from commandButton but is when invoked from an input field?


Ken KoellnerKen Koellner

One of our developers tried to resolve this issue by also putting a rerender attribute on the command button.

<apex:commandButton value="Do It" action="{!doIt}" rerender="none"/>


That looks to have caused a very serious issue that took a long time to debug.  The button then did two AJAX requests, one from the script and one because of the rerender.  The page worked correctly about four out of five times, but one out of five times some items in view state were lost and the page broke.  I suspect the randomness was the result of a race condition in that depending on which request returned first, you got one of the two behaviors.


I believe the fix is definitely not also including a rerender on the commandButton tag.


Hi Ken,


Is commandButton click refreshing your page ?


If yes, try to call the javascript fucntion like this:

<apex:commandButton value="Do It Wrapper" onClick="doItWrapper(); return false;" />



Click Kudos(star icon on left) if this provides you with useful information and mark it as a solution if it solves your problem.


Ken KoellnerKen Koellner

Actually, it's the opposite problem.  The rerender on the actionFunction doesn't refresh the contents.


But wha you said will only work with action= on commandButton.  It doesn't work with rerender= on commandButton.


If you call an onClick() function on commandButton, regardless of what it returns, it will do a server interaction if it has a rerender on it.


I took a look at the generaed JS code in this situation.  There's no conditional.  It calls my JS function, then does the AJAX request.


function onclick(event) { 
doItWrapper();;A4J.AJAX.Submit('myPage:myForm',event,{'status':'myPage:myForm:lookupStatus','similarityGroupingId':'myPage:myForm:j_id227','parameters':{'myPage:myForm:j_id227':'myPage:myForm:j_id227'} } );return false;