2

I would Like to add Error message on visualfocepage if save button logic has error. this part is working ,but i need to show popup if there are no error messages.how to add condition to show popup only if there are no error messages and if error messages found then dont show popup(display only error messages) SUDO:

if(errors==NULL){
showpopup
}else{
show error messages &ignore popup
}


<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:commandButton value="Save" action="{!save}" rerender="showmsg" oncomplete="window.open('/apex/popuppage','_blank','height=400,location=no,resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=1', 1)" />`

controller

if(notAllow){
        Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'record already has an active status'));
} 

2 Answers 2

1

Do one thing

oncomplete of save button call a javascript function and check if notAllow false then open pop up

<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:commandButton value="Save" action="{!save}" 
    rerender="showmsg,scriptPanel" oncomplete="openPage();" />

<apex:outputpanel id="scriptPanel"> 
<script>
function openPage()
{
  if('{!notAllow}' == 'false')
  {
    window.open('/apex/popuppage','_blank','height=400,location=no,resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=1', 1);
  }
}
</script>
<apex:outputpanel>
3
  • Ratan,thanks for the reply. {!notAllow} is not available in VF. its in controller, is there a way to check if error messages are empty
    – Sriram
    Apr 8, 2017 at 15:56
  • @patha make that variable get set, so this variable will be available in vf page.
    – Ratan Paul
    Apr 8, 2017 at 15:58
  • @patha cool....
    – Ratan Paul
    Apr 8, 2017 at 16:14
2

This code will work for you.

Use notAllow attribute in the javascript function at oncomplete function itself.

Visualforce

<apex:page controller="myController2">
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:form>
    <apex:commandButton value="Save" action="{!save}" rerender="showmsg" 
    oncomplete="javacript: if({!notAllow==false})window.open('/apex/popuppage','_blank','height=400,location=no,resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=1', 1)" />`
</apex:form>
</apex:page>

Controller

public boolean notAllow {get;set;}
        public PageReference save()
        {
            notAllow = false; //change it to true to show error message
            if(notAllow){
                Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'record already has an active status'));
            } 
            return null;
        }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.