Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.
<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.

share|improve this question
    
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? –  Lex 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

3 Answers 3

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.

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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