<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.

  • What exactly doesn't work; it Panel not getting rerendered? Is add() not called? If you add oncomplete="alert('test');" to your actionFunction, do you get an alert? Feb 5, 2013 at 10:50
  • did you try rerendering <apex:pagemeesages/> ? There could be some validation error.
    – doga
    Feb 5, 2013 at 11:45
  • add() not called
    – Pankaj
    Feb 5, 2013 at 11:59

4 Answers 4


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.

  • i checked no javascript error is there
    – Pankaj
    Feb 5, 2013 at 12:08
  • Did you do the other things I suggested? Feb 5, 2013 at 12:09
  • actually i want to call an apex method which on clicking on add button adds 1 item in list,that list contain one apex:inputfile element also and then i want to rerender that list.earlier i was doing it with commandbutton but it was giving error that apex:input file cannot be used in conjuction with rerender or oncomplete.so i was trying with apex:outputlink but again i am having same error.do u have any solution for dynamically adding apex:inputfile on VF.
    – Pankaj
    Feb 5, 2013 at 12:26
  • 1
    No, that's not possible. You have to refresh the entire page. Feb 5, 2013 at 12:33
  • ok Bob,i am trying on this if got some solution will post that.one more thing i want to add on, u r very active contributor A Real MVP thanks a lot!
    – Pankaj
    Feb 5, 2013 at 12:37

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

Adding a return false states the browser that no further action associated to the element should be processed, hence it wont reload the page.

  • Worked perfectly! :) Jul 10, 2014 at 15:20

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:
  • hmm, that seems very strange, i use output links without value attributes all the time without issues Mar 7, 2013 at 17:05

enter image description here

It is easy and fast, you just need a javascript function in your apex page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .