function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
wt35wt35 

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&colon;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;
      
   }

 

 

 

 

 

bob_buzzardbob_buzzard

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.

wt35wt35

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:

 

<apex:commandButton value="Mark As Complete" onclick="return confirm('test');" action="{!markPillarAsComplete}" reRender="Merchant_Introduction_Engagement_Section">
                        <apex:param name="pillarName_MarkAsComplete" value="Merchant Intro Engagement" assignTo="{!pillarName_MarkAsComplete}" />
</apex:commandButton>

 

When I click on my button I do get a confirmation pop-up, however the Apex action is not executed....

 

bob_buzzardbob_buzzard

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. 

wt35wt35

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!