You need to sign in to do that
Don't have an account?
Anurag Singh 17
Action function not working
Hi guys have a
page :.
<apex:commandButton value="First" onclick="getscore('First')" />
</apex:pageBlock>
<apex:actionFunction action="{!score}" name="getscore" reRender="content">
<apex:param name="myParam" value=""/>
</apex:actionFunction>
Extension method:
public void score() {
string passedParam1 = Apexpages.currentPage().getParameters().get('myParam');
system.debug('ssssssssssssss'+passedParam1);
}
The method is not being called at all any help here would be appreciated
page :.
<apex:commandButton value="First" onclick="getscore('First')" />
</apex:pageBlock>
<apex:actionFunction action="{!score}" name="getscore" reRender="content">
<apex:param name="myParam" value=""/>
</apex:actionFunction>
Extension method:
public void score() {
string passedParam1 = Apexpages.currentPage().getParameters().get('myParam');
system.debug('ssssssssssssss'+passedParam1);
}
The method is not being called at all any help here would be appreciated
It looks like your code is correct, you are calling actionfunction directly from button onclick with parameter.
But may be arrangement of code is not proper, can you please try to define <apex:actionFunction> above <apex:commandButton> ?
I am not sure but you should try like below.
Please let me know if it works.
Thanks and Cheers,
Jigar
All Answers
It looks like your code is correct, you are calling actionfunction directly from button onclick with parameter.
But may be arrangement of code is not proper, can you please try to define <apex:actionFunction> above <apex:commandButton> ?
I am not sure but you should try like below.
Please let me know if it works.
Thanks and Cheers,
Jigar
Internally the name of actionfunction is working as javascript function name.
Since if we do not define that function before using of it, it will not find that actionfunction name.
I understood that but if i change the command button to outputlabel and use the same code with action function below the output label tags it works fine! so I am a bit confused
@Anurag
Actually the issue is not common which is not replicated every time in every visualforce page, may be your other code effecting it.
If you try to other simple visualforce page and try to replicate the same issue, may be you'll not find it.
But according to best practice we should arrange visualforce page code like below.
<apex:page>
<apex:form>
<style></style>
<script><script>
<apex:actionFunction>
<apex:pageMessages>
<apex:pageBlock>
....
If you use <apex:commandButton onclick="getscore('First')" /> what happens is that you have a "race condition" where the commandButton's built-in functionality will try to fire at the same time as the functionality defined in your onclick method. Another option would be to set your onclick="getscore('First'); return false;" which should prevent the commandButton action from firing.
See here: http://salesforce.stackexchange.com/questions/29400/calling-apexactionfunction-on-apexcommandbuttons-onclick-event
I am facing same issue. i put my action function before outlink but it doesn't work. can you please help me.
<apex:actionFunction action="{!getDetails}" name="accDetails" rerender="display">
<apex:param name="accId" value="" assignTo="{!accid}"/>
</apex:actionFunction>
<apex:outputLink onclick="accDetails('{!a.id}');return false;">
{!a.Name}
</apex:outputLink>
here i am making table for Accounts and a.id is id of an account which i want to pass to my parameter accid in controller. please help me out.
Thank you