3

I would like to use the component apex:actionFunction to set a variable from a custom controller but after the call, the Visualforce page reloads itself. :/

I use return false; on the outputLink component and the rerender attribute but it doesn't work.

This is my code :

Visualforce page :

<apex:form>
        <apex:actionFunction name="setTheSource" action="{!setTheSource}">
            <apex:param name="selectedSource" value="{!$Label.Labs_Sf_Formulaire_QR_Label}" assignTo="{!selectedSource}" />
        </apex:actionFunction>
</apex:form>

<apex:outputLink value="#" id="contactusForm" onclick="setTheSource(); return false; showFeedbackDialog(); return false;" rendered="{!pkbCon.selectedLanguage != 'ru'}" >{!$Label.Labs_Sf_Contact_Us}</apex:outputLink>

Custom controller :

public String selectedSource {get;set;}

public PageReference setTheSource()
    {
        System.debug('SOURCE HERE!!! ' + ApexPages.currentPage().getParameters().get('selectedSource'));
        this.selectedSource = ApexPages.currentPage().getParameters().get('selectedSource');

        return NULL;
}

Have you any idea for why it doesn't work please?

Thanks for the help. :)

2 Answers 2

3

Instead of using false in the rerender attribute, you should just leave is blank. Example rerender="". That has worked for me.

1
  • 1
    It doesn't work for me, Salesforce redirect me. :/ The controller method is not called when I see the debug logs.
    – Oupat
    Apr 23, 2015 at 12:14
0

Try to make setTheSource method void. When you return null from an action method it's normal the VisualForce page to reload.

2
  • I'd be surprised if this matters; I use return type of PageReference in my actionmethods all the time and if I want to refresh the page, I return null.
    – cropredy
    Apr 23, 2015 at 1:32
  • I forgot to tell you that I use a Visualforce component, a Force.com site and knowledge. I tested my code in another organization and it works. A Visualforce page calls a Visualforce component giving its controller. Visualforce Page => Apex controller => Visualforce component. Salesforce tried to redirect me to this URL : /knowledge/TOCArticleRendererPkb.apexp
    – Oupat
    Apr 23, 2015 at 12:09

You must log in to answer this question.

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