11

I'm using <apex:actionFunction> and my page is reloaded. I don't use reRender attribute and I'm wondering if there is a way to prevent page reloading.

Maybe there is a special value to set to reRender ?

EDIT :

Here is my code :

  <apex:page controller="myController">
      <apex:commandButton value="save" onclick="save()"/>

      <script type="text/javascript">

          function save(){
              // Some code
              myMethod('param');
              // Some code
          }  

      </script>
      <apex:form >
          <apex:messages />
          <apex:actionFunction name="myMethod" action="{!controllerMethod}">       
              <apex:param name="param" value="" />
          </apex:actionFunction>  
      </apex:form>
  </apex:page>

And my controller :

 public String controllerMethod() {
     String values = Apexpages.currentPage().getParameters().get('param');
     system.debug('Values : ' + values);

     return values;
 }
0

3 Answers 3

5

If you call the action function just put return false; to the end of the call:

<apex:actionFunction name="myFunction" action="{!someMethod}" /> 

<a href="#" onclick="myFunction(); return false;">Click me</a>

Or based on your code:

<apex:commandButton value="save" onclick="save(); return false;"/>
3
  • I tried your tip but it doesn't work. I post some code.
    – SF_user
    Jun 12, 2014 at 15:04
  • That's what I do but my page still reload !
    – SF_user
    Jun 12, 2014 at 15:23
  • This didn't work for me. Its still reloading Jan 15, 2023 at 7:25
4

What should work in most cases is to just add reRender="", or as Neo suggests rerender="none". It doesn't really matter what is put between the "" as long as it doesn't match the name of any elements on the page.

The way the <actionFunction> tag works is that if there is no reRender attribute defined it refreshes the entire page, but if there is a reRender attribute it only refreshes the elements defined in the tag. So adding reRender="" will lead to nothing being re-rendered, whereas reRender="none" or reRender="false" will re-render the element whose id is none or false, respectively.

Visualforce doesn't strictly enforce that the ids specified in your reRender exist on the page. As a result if that id doesn't exist, it will simply be ignored.

2

In this tag:

<apex:actionFunction name="myMethod" action="{!controllerMethod}">

Add reRender="false" so it ends up being:

<apex:actionFunction name="myMethod" action="{!controllerMethod} reRender="false">

This worked for me!

3
  • It also works to use reRender="none"
    – Neo
    Jun 11, 2015 at 19:47
  • Nope. It doesn't work for me and according to the docs this is not what the reRender attribute is for.
    – JannieT
    Aug 31, 2015 at 13:45
  • This didn't work for me as well. I guess there are no false/true values for rerender. It just picks up for checking the component id and then proceeds with the rerendering. Jan 15, 2023 at 7:28

You must log in to answer this question.

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