<apex:outputLink onClick="test();">Add </apex:outputLink>
<apex:actionFunction name="test" action="{!add}" rerender="Panel"/>
Am i am doing something wrong because action function is not being called.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this community<apex:outputLink onClick="test();">Add </apex:outputLink>
<apex:actionFunction name="test" action="{!add}" rerender="Panel"/>
Am i am doing something wrong because action function is not being called.
Yes, you can do that. An actionfunction simply associates an action method with a javascript function whose name you specify. You can call that javascript function from anywhere that you can call a regular javascript function.
I'd check that there are no validation type errors here - add an apex:pageMessages and rerender that from the actionFunction, otherwise those errors will be swallowed. If you aren't seeing what you expect in the rerendering, turn on debug logging and check your 'add' method is behaving as expected. You could also use the web inspector to confirm that you don't have any other javascript errors that could be interfering with your actionfunction.
Well you can always call a javascript
function from a outputlink
but the catch is you make sure to return false from you onclick method.
<apex:outputLink value="MyValue" onClick="myActionFunction();return false;">
My Link
</apex:outputLink>
Adding a return false
states the browser that no further action associated to the element should be processed, hence it wont reload the page.
The wrong thing here is, that you don't use value
param in the outputLink. Without that the page will be reloaded after click and your actionFunction call will not work. Try to insert javascript:void(0)
as the value:
<apex:outputLink value="javascript:void(0);" onClick="test();">
Test it:
</apex:outputLink>
add()
not called? If you addoncomplete="alert('test');"
to your actionFunction, do you get an alert?