SFDC VF ActionFunction

SFDC VF ActionFunction

Comparing JavaScript Remoting and actionFunction

JavaScript Remoting Example

  • The tag:
    • lets you specify rerender targets
    • submits the form
    • doesn’t require you to write any JavaScript
  • JavaScript remoting:
    • lets you pass parameters
    • provides a callback
    • requires you to write some JavaScript

explain 1

You must specify a rerender attribute in the <apex:actionFunction> tag! Without this the generated function does take any parameters, but as soon as you put it in then it does - even if you just leave it empty, i.e. the below code will generate doStuff(x) {…} Go figure.
1
2
3
<apex:actionFunction name="doStuff" action="{!myAction}" rerender="">
<apex:param name="x" value="x" assignTo="{!m_x}"/>
</apex:actionFunction>

explain 2

ActionFunctionのレンダリングプロパティの記述がないとパラメータがどう頑張っても渡らないのです。つまり
1
2
3
4
5
6
7
<apex:pageBlock id="rerenderPlace">
<apex:actionFunction name="debug" action="{!controllerMethod}" rerender="rerenderPlace">
<apex:param assignTo="{!stringVar}" name="first" value=""/>
</apex:actionFunction>
<apex:commandButton onclick="debug()">
</apex:pageBlock>
つまりというか、rerenderしないとパラメータ渡せないようです。
元々rerenderありきのタグなんでしょうかね。

explain 3

SFDC VF actionfunction

How Can I pass parameters using apex:actionFunction??

There is an example for you
1
2
3
4
5
6
7
<apex:inputHidden value="{!param}" id="tmpNo"></apex:inputHidden>
<script language="javascript">
function changeCategory(tmpVal) {
document.getElementById('{!$Component.tmpNo}').value = tmpVal;
changeCategory1(); //call actionfuntion
}
</script>

SFDC VF ActionSupport

1
2
3
4
5
6
7
8
<apex:repeat value="{!bean.kinds}" var="kind">
<apex:selectList id="kind" size="1" value="{!kind.value}">
<apex:actionSupport action="{!doChangeKind}" event="onchange" rerender="frm">
<apex:param assignTo="{!bean.kindNo}" value="{!kind.index}" name="kindNo"/>
</apex:actionSupport>
<apex:selectOptions value="{!kind.options}" />
</apex:selectList>
</apex:repeat>