1

EDIT: I needed to put a ReRender, but why?


Trying to pass an action function param to the VFP's custom controller. The value is not passing as passedVariableString returns null on the debug. Where am I going wrong?

Initiated in between script tags on VFP:

var variable = 'some text here';
launchActionFunction(variable);

On same VFP:

<apex:actionFunction action="{!launchActionFunction}" name="launchActionFunction">
       <apex:param name="passedVariable" value=""/>
</apex:actionFunction>

On Controller

public void launchActionFunction()
    {
    string passedVariableString = 
    system.CurrentPageReference().getParameters().get('passedVariable');
    system.debug(passedVariableString);
    }
2
  • 1
    I'm sorry, I marked this as duplicate before I saw the edit. You have a solution, but are you interested in the why? I can reopen this if that's the case.
    – sfdcfox
    Jul 12, 2018 at 23:06
  • 1
    @sfdcfox - I believe that S.B needed to know why he needs to put the reRender because he mentioned in the Edit. As per my head, you can open the question so that he can get the answers for his Why?
    – Amit Singh
    Jul 13, 2018 at 3:54

2 Answers 2

4

Salesforce has built the framework for apex:actionFunction like that way that it expects rerender attribute to pass value to the controller and the ID of one or more components that are redrawn when the result of the action method returns to the client.

If you don't want to rerender anything, then use rerender="none".

<apex:actionFunction action="{!launchActionFunction}" name="launchActionFunction" rerender="none">
       <apex:param name="passedVariable" value=""/>
</apex:actionFunction>

For more information, refer apex:actionFunction

3

Please find below updated controller code which might help you :

On Controller:

Declare a public variable with name as "passedVariable":

public String passedVariable{get;set;}

Make sure that you have getter and setter in place.

Then you can simply access the value from VF page as below :

public void launchActionFunction()
    {
    system.debug(passedVariable);
    }

Using reRender is optional.

VF Page :

<apex:actionFunction action="{!launchActionFunction}" name="launchActionFunction">
       <apex:param name="passedVariable" value="" assignto="{!passedVariable}"/>
</apex:actionFunction>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .