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
Abhik DeyAbhik Dey 

Oncomplete issues with apex commandButton

Folks.

I am using <apex:commandButton value="Next" action="{!method1}" rerender="test" oncomplete="complete1();"/>

Once the method1 executes, it updates a boolean variable to 'true' and in the constructor this variable value is set as false

public void method1(){
                fieldstatus='true';
                //system.debug('fieldstatus:'+fieldstatus);
    }
Now on VF page , i want to access this variable value so used oncomplete, but in the oncomplete function i always got the value as false.

function complete1() {
        var check1= '{!fieldstatus}';
        alert(check1);
        }

Any idea why this wierd behaviour?
 
Best Answer chosen by Abhik Dey
Keshab AcharyaKeshab Acharya
I see you are rerendering "test". If its a output panel. try to keep the JS inside output panel. it will work. see below the code.

Controller:-
public class Apex{
    public boolean test{get;set;}
    
    public Apex(){
        test = false;
    }
    public void method1(){
        test = true;
    }
}
Page:-
<apex:page showHeader="false" controller="Apex">
<apex:outputPanel id="tst">
<script>
    function complete1() {
        var check1= '{!test}';
        alert(check1);
        }
</script>
<apex:form>
<apex:commandButton value="Next" action="{!method1}" rerender="tst" oncomplete="complete1();"/>
</apex:form>
</apex:outputPanel>
</apex:page>

Mark as answer if it helps you.

 

All Answers

Keshab AcharyaKeshab Acharya
I see you are rerendering "test". If its a output panel. try to keep the JS inside output panel. it will work. see below the code.

Controller:-
public class Apex{
    public boolean test{get;set;}
    
    public Apex(){
        test = false;
    }
    public void method1(){
        test = true;
    }
}
Page:-
<apex:page showHeader="false" controller="Apex">
<apex:outputPanel id="tst">
<script>
    function complete1() {
        var check1= '{!test}';
        alert(check1);
        }
</script>
<apex:form>
<apex:commandButton value="Next" action="{!method1}" rerender="tst" oncomplete="complete1();"/>
</apex:form>
</apex:outputPanel>
</apex:page>

Mark as answer if it helps you.

 
This was selected as the best answer
Abhik DeyAbhik Dey
cool done
archie333archie333
it helps me a lot......thanks bro !!