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
hgolovhgolov 

Action Function not calling the function referenced in action attribute

Hi All,

Firstly, thanks for taking the time to look at my post.

I have  vf page that was working very nicely until recently (maybe until spring '11 was launched?). Now, when the user fires an event that calls an actionFunction, the apex method is not being called. I put an actionStatus component into the page to show the status, and it does show the start and stop text, but the debug log shows output appropriate for pageload, not for the method referenced in the actionFunction tag.

Action Function Tag:

 

<apex:actionFunction status="counterStatus" name="renderField" action="{!renderField}" immediate='true' rerender="taskInfoDisplay, descInfo,fundraisingInfo, sysInfo, editButtons">
  <apex:param name="fieldToShow" value=""/>
  </apex:actionFunction>

 

 

Apex Method:

 

public void renderField(){
		System.debug('in renderField');
		fieldToEdit = ApexPages.currentPage().getParameters().get('fieldToShow');
		isEdit = true;
		System.debug('the field to edit is: ' + fieldToEdit);
	}

 

 

Sample Calling Code:

 

<apex:outputLabel ondblclick="renderField('Priority')"  value="Priority"/>

 

 

Does anyone have any ideas as to why this would no longer work?

 

Thanks!

 

Best Answer chosen by Admin (Salesforce Developers) 
hgolovhgolov

Thanks everyone for your time, patience and suggestions. I took apart the vf code and put it together piece by piece, and it worked. I still don't know why it didn't work originally, but it's ok now.

All Answers

SteveBowerSteveBower

Does anything change if you alter the Apex renderField() to return a pageReference of null instead of a void?     Best, Steve.

hgolovhgolov

Thanks for taking the time to answer. No, it doesn't change anything....

Bhawani SharmaBhawani Sharma

Try with the following :

 

 

<apex:actionFunction status="counterStatus" name="renderField" action="{!renderField}" immediate='true' rerender="taskInfoDisplay, descInfo,fundraisingInfo, sysInfo, editButtons">
<apex:param name="fieldToShow" value="" assignedTo="{!fieldToEdit}"/>
</apex:actionFunction>

 

public void renderField(){
isEdit = true;
System.debug('the field to edit is: ' + fieldToEdit);
}
<apex:outputLabel ondblclick="renderField('Priority');return false;"  value="Priority"/>

 

 

 

 

hgolovhgolov

Thank you Bhawani for trying this out.

 

Unfortunately, it didn't help. I also tried to rename the javascript function (name attribute of the actionFunction tag) because it matched the apex method name, but that didn't help. In further examining the system log, it seems that all that happens is the re-rendering of the appropriate components, but it never gets into the method renderField.

I tried the following, which in effect bypasses the apex method:

<apex:actionFunction status="counterStatus" name="jsRender" action="{!renderField}" immediate="true" rerender="taskInfoDisplay, descInfo,fundraisingInfo, sysInfo, editButtons">
  <apex:param name="fieldToShow" value="" assignTo="{!fieldToEdit}"/>
  <apex:param name="inlineEdit" value="true" assignTo="{!isEdit}"/>
  </apex:actionFunction>

but based on the output from the actionStatus component, neither of the member properties are being changed.

 

Any other suggestions?

Bhawani SharmaBhawani Sharma

I hope, there is no any fucntion named "jsRender" in javascript.

Can you please confirm ?

BeeddiskShahBeeddiskShah

Err... buddy, will you try removing immediate='true' please don't add this attribute on Action Function.

BeeddiskShahBeeddiskShah
<apex:actionFunction status="counterStatus" name="renderField" action="{!renderField}" immediate='true' rerender="taskInfoDisplay, descInfo,fundraisingInfo, sysInfo, editButtons">
  <apex:param name="fieldToShow" value=""/>
  </apex:actionFunction>
hgolovhgolov

No, there was no other function named jsRender.

hgolovhgolov

That didn't help. Why shouldn't this be used? It's in the docs.

Imran MohammedImran Mohammed

Sounds odd with the question i am posing, but this is what happened to my VF page post Spring 11 release.

Are you using any sObject.id thats assigned to value attribute of any of the apex tags?

If so, try removing that.

hgolovhgolov

Thanks Imran, but no, I'm not assigning an id as a value to any apex tags. I am assigning an id to a apex property - do you think that would make a difference?

 

Imran MohammedImran Mohammed

I would recommend to include apex:pageMessages tag and then rerender after the actionFunction you are invoking.

if there is an issue, that will be displayed.

What is the data type of the property you are assigning id value to?

Idd BaksheeshIdd Baksheesh

The immediate='true' runs all the javascripts mentioned in the tag BEFORE hitting the server.

 

Normal excecution is:

 

Action function-> ServerSide JS (like validation etc)->OnClick->Action

 

Using immediate='true' makes it

 

Action function-> OnClick->ServerSide JS->Action

 

this also didn't work? Hold on let me run your code

hgolovhgolov

 

I would recommend to include apex:pageMessages tag and then rerender after the actionFunction you are invoking.

if there is an issue, that will be displayed.

What is the data type of the property you are assigning id value to?
Regards,
- Imran

 

No, this doesn't display any messages. Any other ideas?

 

hgolovhgolov

 

The immediate='true' runs all the javascripts mentioned in the tag BEFORE hitting the server.

 

Normal excecution is:

 

Action function-> ServerSide JS (like validation etc)->OnClick->Action

 

Using immediate='true' makes it

 

Action function-> OnClick->ServerSide JS->Action

 

this also didn't work? Hold on let me run your code
Cheers,
Sid

 

 

Thanks for the explanation. I tried that, and it also didn't work...

Idd BaksheeshIdd Baksheesh

 

Your VF page:
 
<apex:actionFunction status="counterStatus" name="renderField" action="{!renderField}" immediate="true" rerender="taskInfoDisplay, descInfo,fundraisingInfo, sysInfo, editButtons">
     <apex:param name="fieldToShow" value="{!fieldToEdit}"/>
  </apex:actionFunction>
  <apex:outputLabel onclick="renderField('priority')" value="Priority"/>
 </apex:form>
</apex:page>
<apex:page controller="testing"><apex:form > <apex:actionFunction status="counterStatus" name="renderField" action="{!renderField}" immediate="true" rerender="taskInfoDisplay, descInfo,fundraisingInfo, sysInfo, editButtons">     <apex:param name="fieldToShow" value="{!fieldToEdit}"/>  </apex:actionFunction>  <apex:outputLabel onclick="renderField('priority')" value="Priority"/>

 

 

 

Your Controller

 

 

 

public class testing {
Public string fieldToEdit {get;set;}
public void renderField(){
        System.debug('in renderField');
        fieldToEdit = ApexPages.currentPage().getParameters().get('fieldToShow');
        Boolean isEdit = true;
        System.debug('the field to edit is: ' + fieldToEdit);
//        return null;
    }
}

 

This is working, do change the event to dbl click, i used it only for testing.

 

 

Idd BaksheeshIdd Baksheesh

The only thing I found mis-match was the Apex:Param which was causing a javascript error. This fixed it. Make the fieldtoEdit public with get;set; in controller.

 

<apex:param name="fieldToShow" value="{!fieldToEdit}"/> 
hgolovhgolov

Thanks so much for taking the time to test this for me.

Your code worked perfectly when I tested it on it's own, but when I tried to put it back into my controller and page, it still didn't call the method. Any suggestions?

SteveBowerSteveBower

Can you post it all?  You're not even seeing your system.debug() at the start of your method, so it seems there's something wider that the code here that's impacting it.   Best, Steve.

Idd BaksheeshIdd Baksheesh

Yes agreed with Steve, some other javascript is failing in your page stopping all the javascripts.

SteveBowerSteveBower

If you turn on the Javascript Console in your debugger do you see any errors?  I sort of assumed you looked there already, but perhaps not.   -Steve

Idd BaksheeshIdd Baksheesh

The only problem in the above code I saw was the use of value='' as blank. If there is any other js error on the page, it will  prevent it from executing any other scripts.

 

Like steve said, check the error console, or if possible review your complete code. The problem is somewhere else/

hgolovhgolov

 

If you turn on the Javascript Console in your debugger do you see any errors?  I sort of assumed you looked there already, but perhaps not.   -Steve

 

It seems that the viewState parameters in the request are causing issues for Firebug ".. Firebug request size limit has been reached by Firebug. ...", but should that effect the code itself? I'm not seeing any other js errors.

 

hgolovhgolov

 

Can you post it all?  You're not even seeing your system.debug() at the start of your method, so it seems there's something wider that the code here that's impacting it.   Best, Steve.

 

 

I think I'm going to take this from the top and build the page again line by line. It really hurts to do this because I've spent many hours already, but I think at this point it's my only option. I'll keep you guys posted.

Thanks for all your time and effort.

Imran MohammedImran Mohammed

You can go with scratch again, but will still recommend if you can post the code so that it can be answered if anything is wrong.

hgolovhgolov

Thanks everyone for your time, patience and suggestions. I took apart the vf code and put it together piece by piece, and it worked. I still don't know why it didn't work originally, but it's ok now.

This was selected as the best answer
hattihatti

Thanks a ton for this info. This really helped me.

RuneWaageRuneWaage

We faced the same issue in our project, the solution we found was quite easy, but I am not able to explain why it is working.

The solution was to simply put a new "form" element around the actionFunction tag.

vanessenvanessen

for my case, I tried to use your code, but was not able to work, so i discovered that when using immediate=true with actionfunction, we must assign values to the apex function via apex:param,(thanks to Idd bakheesh) like this :

 

<apex:selectRadio id="choose12_InsuredOwner" value="{!PolicyOwnershipStatementInsuredOwner.selected12a}" onclick="checkMandatory(this.value);">
                                            <apex:selectOption itemValue="true" itemLabel="Yes"/>
                                            <apex:selectOption itemValue="false" itemLabel="No"/>
                                        </apex:selectRadio>

 

<apex:actionFunction name="checkMandatory" action="{!CheckMandatorySection12}" immediate="true" rerender="main" status="status001">
                            <apex:param value="" name="param1" assignTo="{!PolicyOwnershipStatementInsured.selected12a}" />
</apex:actionFunction>

 

then it works.

Andrew B. DavisAndrew B. Davis
Just to second what RuneWaage said above, I was having this problem with many actionFunctions, and the solution was to break the page into several <apex:form> elements, surrounding the ActionFunction and the fields directly related to it.