[SalesForce] pass actionFunction name of variable to set in controller

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?

Best Answer

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"
        oncomplete="oTable.fnAddData({!tableData});">
    <apex:param name="sd" assignTo="{!selectedDivision}" value="" />
</apex:actionFunction>

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

Related Topic