I have VF page shown in the service console. When Apex command button is clicked it is invoking controller action method. OnComplete on the command button executes the JS function which refreshes the Tab in the service console. Controller action method does validation and if validation fails it creates entry to be shown in ApexPageMessage and returns null.
Ideal Behavior
When Command button is clicked - action method is called, if validation fails, Apex Page Message should display the error on the page and OnComplete JS should not be invoked.
ISSUE
When command button is clicked - action method is called and if validation fails, the pagemessage is not shown on the Page. Instead JS function is called.
How do I make sure PageMessage are displayed when OnComplete Js is used.
NOTE
Everything works as expected if I remove the "OnComplete" JS from Commandbutton.
Markup
<apex:commandButton value="ClickMe" action="{!Save}" oncomplete="refreshConsoleTab('{!IsValid}');"/>
Code
public PageReference Save()
{
if(validationFailure)
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Validation failed'));
return null;
}
else
{
//DML statements ;
return null;
}
}