0

I don't need to close the page when it is having a pageMessage on a vf page. if it doesnt have any message then the page has to close automatically... following is the page...

<apex:page showHeader="false"  controller="GSDLocateQueueController" sidebar="false" cache="true" docType="html-5.0">

    <script type="text/javascript">
    window.returnValue = null;
    var returnedArray = new Array();
    function callParentPage(queueID,queuename) 
    {

        window.opener.SetValueOnParentPage(queueID,queuename);
        window.close();
    }
    </script>
    <apex:form >
    <apex:pageBlock >
   <!-- Page Block Buttons (START) -->
   <!--<apex:outputPanel id="ErrorMessage" rendered="{!renderErrorMessage}" ><b>The queue value is:{!manualQID}</b></apex:outputpanel>-->
     <apex:pageMessages id="ErrorMessage" rendered="{!renderErrorMessage}"></apex:pageMessages>
    <apex:pageBlockButtons >
      <apex:outputPanel id="customButtons" >
      <apex:commandButton value="OK" action="{!checkQ}" onComplete="javascript:callParentPage('{!JSINHTMLENCODE(manualQID)}','{!JSINHTMLENCODE(manualQName)}');" reRender="ErrorMessage"/>   
      <apex:commandButton value="{!$Label.GSD_PsaCancelButton}" onclick="window.close();" />
      </apex:outputPanel>
    </apex:pageBlockButtons>
    <!-- Page Block Buttons (START) -->

    <!-- Outer Panel (START) -->
    <apex:outputPanel id="outer">
     <table cellpadding="10" style="table-layout:auto;width: 100%;">
                    <tr>
                        <td><apex:outputLabel value="System Generated Queue"/></td>
                        <td><apex:inputText value="{!systemGenQueueName}" id="queueName" disabled="true"/></td>   

                    </tr>
                    <tr>
                       <td><apex:outputLabel value="Manually Overide Queue"/></td>
                        <td><apex:inputText value="{!manualQName}" id="manualOverrideQ" /></td> 
                    </tr>    
      </table>        
      </apex:outputpanel>

    </apex:pageBlock>

    </apex:form>
    </apex:page>

Controller:

public with sharing class GSDLocateQueueController {

public PSA_Assignment_Rules__c psaAssignmentRule{get;set;}

public string queue {get;set;}
public string systemGeneratedQ {get;set;}
public string manualQID {get;set;}
public string manualQName {get;set;}
public string queueAssigned {get;set;}
public string systemGenQueueName {get;set;}
public string systemGenQueueID {get;set;}
public string defaultQueueName;
public static List<group>listQueue;
public List<PSA_Assignment_Rules__c> listRules;
public Boolean renderErrorMessage {get;set;}
public string returnQueue {get;set;}

Public String validatedQueue {get;set;}

public GSDLocateQueueController()
{
    renderErrorMessage=true;
    //flag=false;
    String role = ApexPages.currentPage().getParameters().get('role');
    String region = ApexPages.currentPage().getParameters().get('regionId');
    String practice = ApexPages.currentPage().getParameters().get('practiceId');
    String deliveryMethod= ApexPages.currentPage().getParameters().get('deliveryMethod');
    String productFamily = ApexPages.currentPage().getParameters().get('productFamily');
    string account = ApexPages.currentPage().getParameters().get('AccountId');

    system.debug('GSDLocateQueueCtrl:role>>>'+role ); 
    system.debug('GSDLocateQueueCtrl:regionId>>>'+region ); 
    system.debug('GSDLocateQueueCtrl:practiceId>>>'+ practice); 
    system.debug('GSDLocateQueueCtrl:deliveryMethod>>>'+ deliveryMethod); 
    system.debug('GSDLocateQueueCtrl:productFamily>>>'+productFamily );
    system.debug('Account>>>'+Account); 

    pse__Resource_Request__c resReq =new pse__Resource_Request__c();
    resReq.pse__Resource_Role__c=role;
    resReq.pse__Region__c=region;
    resReq.pse__Practice__c=practice;
    resReq.GSD_Delivery_Method_1__c=deliveryMethod;
    resReq.GSD_Product_Family_1__c=productFamily;
    system.debug('resReq-->'+resReq);
    GSD_Security.PSAAssignmentEngineRR rr= new GSD_Security.PSAAssignmentEngineRR();
    systemGenQueueName=rr.getRRQueue(resReq);
    system.debug('manual queue name-->'+systemGenQueueName);


   }
   /** Thsi method will be called on Click of 'OK' button, Returns 'true' on finding the manually entered Queue, else return 'false' **/
        public void checkQ() 
        {
            if(String.isNotBlank(manualQName)){
            system.debug('Manually Override Queue>>>'+manualQName );
            listQueue=[select id,name from Group where type='Queue' AND Name=:manualQName];
            system.debug('GSDLocateQueueCtrl:listQueue size>>>'+listQueue.size());
            if(listQueue.size()>0)
            {

                system.debug('GSDLocateQueueCtrl:manual Queue name, ID>>>'+listQueue[0].name+','+listQueue[0].id);
                manualQName=listQueue[0].name;
                manualQID=listQueue[0].id;
                //return null;
            }
            else
            {

                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Manually Override Queue is not valid Queue,Please re-enter the queue name'));
                // get default qname from managed package custom setting
                manualQName=systemGenQueueName;
                manualQID=[select id,name from Group where type='Queue' AND Name=:systemGenQueueName limit 1].id;
                system.debug('Manual entered Q is not valid.Final Qname, Qid:>>>'+manualQName+','+manualQID);
                //return null;
           }

          }
          else{
                manualQName=systemGenQueueName;
                 manualQID=[select id,name from Group where type='Queue' AND Name=:systemGenQueueName limit 1].id;
                system.debug('Manual entered Q is not valid.Final Qname, Qid:>>>'+manualQName+','+manualQID);

          }
   }
   }
5
  • do you want to show an alert message before redirect a page ? – Ratan Paul Dec 12 '15 at 6:31
  • yes . whenever their is a vf page message i need to stop the window.close() function to work – srini Dec 12 '15 at 6:34
  • you can show an warning JavaScript alert message when user try to close that page. this will work for you? – Ratan Paul Dec 12 '15 at 6:38
  • yes this will work, whenever but whenever the user clicks on ok button without entering the manually override queue, the page has to close. when user enters manually override queue and clicks on OK ,after validating if their exists any warning message on the page then page should not close – srini Dec 12 '15 at 6:41
  • check my answer. You need to set formSubmitting value dynamically – Ratan Paul Dec 12 '15 at 6:48
0
<script>
var formSubmitting = false;


window.addEventListener("beforeunload", function (e) {

    if (formSubmitting) {
        return undefined;
    }

    var confirmationMessage = 'It looks like you have been editing something. '
                            + 'If you leave before saving, your changes will be lost.';

    (e || window.event).returnValue = confirmationMessage; //Gecko + IE
    return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
});

</script>

You can use this code in VF page. What you can do if page message is not present in VF page then make formSubmitting to true. so when user try to leave the page then he will not get warning message.

if page message is present in VF page then make formSubmitting to false. so when user try to leave the page then he will get warning message.


Edit

Whatever your are checking in controller. You can do it in JavaScript(check all the fields empty or not). Based on that set formSubmitting. You dont have to use controller for validation.

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.