Is it possible to pass the actionFunction the name of variable you want it to set in the controller? Right now I need a separate actionFunction for each field I'm setting onChange. Is it possible to make it more generic where the actionFunction receives the variable name and the variable value to set in the controller?

I don't see how this would be possible, but could it be accomplished through javascript remoting?

  • 1
    As far as I know Javascript remoting will not work, it is stateless and its controller methods need to be static. It works without sending the viewstate back and forth. Nov 15 '12 at 15:50
  • How about using the param and setting with action function? Nov 15 '12 at 15:56

Yes, you can use apex:param(s) inside the actionFunction to send values into the controller. The value attribute can be a controller variable as shown in the docs example or set with a javascript call.

Here is something I put in use recently-

<apex:actionFunction name="setTableData" action="{!setTableData}"
        immediate="true" rerender="pgMsgs, matrixTopPanel"
    <apex:param name="sd" assignTo="{!selectedDivision}" value="" />

which is called from javascript with setTableData(j$(this).val());

  • I think you should qualify the use of immediate="true" here - that will not apply any other changes made by the user to the viewstate. Nov 15 '12 at 16:31
  • In this example your actionFunction is always setting the value of selectedDivision. What I'm trying to do is pass in the name of the variable I'm setting. For example passing in 'selectedDivision'. I don't believe this is possible with actionFunction.
    – Phil B
    Nov 15 '12 at 16:31
  • 2
    You'd have to pass two parameters - one the name, one the value, and then your action method would handle setting the value to the appropriate property. Nov 15 '12 at 16:38
  • Sorry for creating some confusion. I am in a learning process myself with all this and do realize I sometimes give steps 1 & 2 and then jump straight to 10 or, as in this case, stop too early. @BobBuzzard thanks for keeping me straight.
    – zjeh
    Nov 15 '12 at 16:59
  • The example I provided is from a VF page heavy with JavaScript processing (large amount of data, render time not an issue). It is something I had handy and thought would show use of param tag. I failed to consider the snip as a whole and the irrelevance of the attributes used with the actionFunction. My apologies. (if you can hang with me, I'll get there eventually)
    – zjeh
    Nov 15 '12 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.