<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? – rael_kid Feb 5 '13 at 10:50
  • did you try rerendering <apex:pagemeesages/> ? There could be some validation error. – doga Feb 5 '13 at 11:45
  • add() not called – Pankaj Feb 5 '13 at 11:59

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.

| improve this answer | |
  • i checked no javascript error is there – Pankaj Feb 5 '13 at 12:08
  • Did you do the other things I suggested? – Bob Buzzard Feb 5 '13 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 '13 at 12:26
  • 1
    No, that's not possible. You have to refresh the entire page. – Bob Buzzard Feb 5 '13 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 '13 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.

| improve this answer | |
  • Worked perfectly! :) – Juan Alvarez Jul 10 '14 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:
| improve this answer | |
  • hmm, that seems very strange, i use output links without value attributes all the time without issues – Ralph Callaway Mar 7 '13 at 17:05

enter image description here

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.