0

I have 2 vf and 2 controllers pages message and download button is there in my search vf page n controller code is here

VF

<apex:page standardController="Detail__c" extensions="MazeChangesSearchController" title="maze Changes Search" docType="html-5.0" readOnly="true"><apex:form id="form">

    <apex:outputPanel styleClass="headerStyle"> 
    <apex:pageBlock id="pageBlock" title="maze Changes Search">
           <apex:outputPanel id="pageMessagePanel">

                    <apex:pageMessages id="pageMessage" />
          </apex:outputPanel>
      <div class="row" align="center"> 
            <apex:outputpanel id="mazeChangesButton">
                 <apex:commandButton action="{!dummy}" onclick="setHiddenmaze();" rerender="false"  value="Download" status="loadStatus" id="download"></apex:commandButton>
            </apex:outputpanel>
        </div>
        <br/>
           <apex:actionFunction name="mazechangesFunction" action="{!mazechanges}" rerender="pageMessage"></apex:actionFunction>
                </apex:pageBlock >

    </apex:outputPanel>
</apex:form><script type="text/javascript">

    function setHiddenmaze({mazechangesFunction();
    }
 }
</script>
</apex:page>

Contoller

 public PageReference mazechanges(){
       PageReference pageRef;
       List<maze__c> mazecount=[Select id from maze__c];

       if(mazecount.size()==0){

          ApexPages.addmessage(new ApexPages.Message(ApexPages.severity.INFO,'Cannot download file since there are no maze changes for the selected date range')); 
       }
       else{
          //ApexPages.getMessages().clear();
          system.debug('employerName='+empname);
          system.debug('mazeMonthFrom='+mazeMonthFrom);
          system.debug('mazeMonthTo='+mazeMonthTo);
          pageRef = new PageReference('/apex/DownloademazeChanges');
          pageRef.setRedirect(true);
          pageRef.getParameters().put('employerName','empname');
          pageRef.getParameters().put('mazeMonthFrom',mazeMonthFrom);
          pageRef.getParameters().put('mazeMonthTo',mazeMonthTo);

          system.debug('pageRef='+pageRef);
       }
       return pageRef;
}

whene i try to search and list count is zero page message is getting displayed correctly but if i try to search again with proper data file is getting downloaded but message is not getting cleared.

3
  • Try adding ApexPages.getMessages().clear(); in the else part.
    – AslamK
    Apr 1 '16 at 12:00
  • i had tried that but message din't get chanage as u can can see the commented part
    – jeetZ
    Apr 1 '16 at 12:22
  • If I remove page reference part it works perfectly fine.
    – jeetZ
    Apr 1 '16 at 12:23
4

Replace rerender="false" with rerender="pageMessagePanel" in apex:commandButton

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.