1

It looks like the state of the controller from the ActionPoller is separate from the state of the controller in the actual page. Below, I have set up a very simple visualforce page. When the page is initialized, FLAG is set to false. When the first button is clicked, FLAG is set to true. When the second button is clicked, the value of FLAG is printed to the debug log. The actionpoller calls a method every 5 seconds which prints FLAG to the debug logs.

Test.vfp

<apex:page sidebar="false" showHeader="false" controller="DebugAPEX" >
<script type="text/javascript">
    function myTest(){
        func(); 
    }
    function myTest2(){
        poll(); 
    }
</script>
    <apex:form>
        <apex:commandButton styleClass="slds-button slds-button_neutral" onclick="myTest()" value="submit" />
        <apex:commandButton styleClass="slds-button slds-button_neutral" onclick="myTest()" value="check" />
        <apex:actionFunction action="{!test1}" name="func" reRender="" />
        <apex:actionFunction action="{!poll1}" name="poll" reRender="" />
        <apex:actionPoller action="{!poll1}" reRender="" interval="5" />
    </apex:form>
</apex:page>

DebugAPEX.apxc

public class DebugAPEX {

    public boolean flag { get; set; }
    public DebugAPEX() {
        System.debug('init');
        flag = false;
    }

    public pageReference test1() {
        flag = true;
        System.debug('setting');
        System.debug(flag);
        return null;
    }
    public pageReference poll1() {
        System.debug('poll check');
        System.debug(flag);
        return null;
    }
    public pageReference check1() {
        System.debug('button check');
        System.debug(flag);
        return null;
    }
}

The logs show

init
poll check
False
setting
True
poll check
False
button check
False

which means the state of the controller is not preserved across actions. I might be completely misunderstanding how the controller and visualforce pages work here, how could I make it so that the flag stays true for all of the actions?

1 Answer 1

3

You're actually cancelling the actionFunction, because the commandButton has no reRender attribute. This means that the form is submitted to the server and the page is refreshed. In order to avoid this behavior, you need to cancel the form submission, which is done by returning false in the onclick handler.

<apex:commandButton 
    styleClass="slds-button slds-button_neutral" 
    onclick="myTest(); return false" value="submit" />

You must log in to answer this question.

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