You need to sign in to do that
Don't have an account?
wt35
apex:actionFunction not working
I need to use the actionFunction tag to perform validation first in JS and then launch a controller method.
The controller method returns a new page reference.
However it seems my controller method is not called...
VF: ( I did not include validation yet as first I want the method call working)
<apex:page controller="HelloWorld"> <apex:form > <apex:actionFunction name="myChange" action="{!change}" rerender=""/> <apex:commandButton value="Warning" onclick="javascript:confirmation();"/> </apex:form> <script> function confirmation() { myChange(); } </script> </apex:page>
Apex method:
public PageReference change(){ System.debug('#######WORKS'); PageReference pageRef = new PageReference('/apex/HelloWorld'); pageRef.setRedirect(true); return pageRef; }
I suspect its because of the rerender attribute - that tells VF to apply the changes to the existing page. Remove that and the page should refresh correctly.
I have actually had another solution in another post (I was trying to have a pop-up asking if the user really wants to continue):
http://boards.developerforce.com/t5/Visualforce-Development/apex-commandButton-Confirm-pop-up-box-before-proceeding/m-p/708293
So I used the "return confirm" statement in the onclick attribute, which worked very well on my test page.
However I am wondering if it is because I have added an apex:param inside the button:
When I click on my button I do get a confirmation pop-up, however the Apex action is not executed....
I would expect your action method to execute, but as you have specified the rerender attribute you won't be able to redirect to a different page.
When I remove "rerender" the warning and action work well.
But now I have a dilemma:
Basically I have a section that show some records and my "Complete" button.
When clicking on that button, the action method marks all these actions as Complete and returns a PageRefefernce so that a full page refresh is done. The problem is that the updated actions do no display if I don't rerender the appropriate section (which I never understood since it is a full page refresh, hence a rerender should not be needed).
Now the business asks for a warning pop-up before proceeding, which I can implement thanks to your solution (using onclick="return confirm..."
But now I need to find a solutiuon where I can use onclick and rerender at the same time...
Do you have any ideas?
Thanks!