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
Onur KayaOnur Kaya 

Visualforce Page Redirection Issue

I have an inline VF page that has two date fields. I prepopulate the dates and when I click on command button it redirects the page into pdf visualforce page. Everything works fine except parameters picked up in URL in the scond run. 

Here is my controller
 
public class FundReportController {


    public Opportunity TempOpportunity {get;private set;}
    
    public final Fund__c f;
    
    public date beginingDate{
    
    get{
        date currentDate = Date.today();
        date beginingDate;
        integer ThisYear = currentDate.year();
        integer LastYear = currentDate.year() - 1;

        if(currentDate.month() > 9){   
           beginingDate = date.newInstance(ThisYear,10,1);
        }else{
           beginingDate = date.newInstance(LastYear,10,1);
        }
      
        return beginingDate;
        }
    set;
    
    }
    
    public FundReportController(ApexPages.StandardController controller){
     
         this.f = (Fund__c)controller.getRecord();
         
         TempOpportunity = new Opportunity();
         TempOpportunity.FS_Disbursement_Request_Date__c = beginingDate;
         TempOpportunity.Board_Poll_Date__c = date.today();
     
     }
     
     public PageReference FundReportPage(){
     
     Pagereference pagereference=new Pagereference('');
     return null;
     
     
     }
}

This is the Visualforce page.
 
<apex:page standardController="Fund__c" extensions="FundReportController">
  <apex:form>
      <apex:pageBlock title="Sample Title" id="block" mode="edit">
          <table border="1" bordercolor="#E5053A" style="background-color:#D7ECF3" width="100%" >
          <tr>
              <th witdh = "50%">Begining Date</th>
              <th witdh = "50%">Ending Date</th>
          </tr>
          <tr>
              <td><apex:inputField id="BegDate" value="{!TempOpportunity.FS_Disbursement_Request_Date__c}" label="" required="true"/></td>
              <td><apex:inputField id="eEndDate" value="{!TempOpportunity.Board_Poll_Date__c}" label="" required="true"/></td>
          </tr>
          </table>
          <apex:commandButton value="GeneratePDF" action="{!FundReportPage}" onclick="window.open('/apex/FundReport?id={!Fund__c.Id}&BegDate={!TempOpportunity.FS_Disbursement_Request_Date__c}&EndDate={!TempOpportunity.Board_Poll_Date__c}','_blank','height=600,location=no,resizable=yes,toolbar=yes,status=no,menubar=yes,scrollbars=1', 1)"/>
      </apex:pageBlock>
  </apex:form>
  
  
</apex:page>

Thank you in advance,
O Kaya
Best Answer chosen by Onur Kaya
Onur KayaOnur Kaya
Hi Ash and James,

I ended up adding actionSupport. So when I update the date fields it reRenders the form and when I click on the generatePDF button right parameteres are being populated.

Thank you both. 
 
<td><apex:inputField id="BegDate" value="{!TempOpportunity.FS_Disbursement_Request_Date__c}" label="" required="true">
                  <apex:actionSupport action="{!FundReportPage}" event="onchange" reRender="block" />
                  </apex:inputField></td>
              <td><apex:inputField id="eEndDate" value="{!TempOpportunity.Board_Poll_Date__c}" label="" required="true">
                  <apex:actionSupport action="{!FundReportPage}" event="onchange" reRender="block" />
              </apex:inputField></td>

 

All Answers

James LoghryJames Loghry
No idea what you're trying to accomplish here, but try adding a rerender="block" to your commandButton, to rerender the page block and update the variables / parameters for the "second run".
AshlekhAshlekh
Hi,

Don't know why you are calling FundReportPage function through the button as nothing is happening in the fucntion.

So you can remove thte action from button and just call a javascript function on onclick and pass the value which you need to be required.
 
<script>
function redirecUser(Fund__c,Disbursement_Request_Date__c,Board_Poll_Date__c)
{
window.open('{!$Page.FundReport}?id='+Fund__c+'&BegDate='+Disbursement_Request_Date__c+'&EndDate='+Board_Poll_Date__c+','_blank','height=600,location=no,resizable=yes,toolbar=yes,status=no,menubar=yes,scrollbars=1', 1)"

}
<script>
apex:commandButton value="GeneratePDF"  rerender="none" onclick="redirecUser('{!Fund__c.Id}','{!TempOpportunity.FS_Disbursement_Request_Date__c}','{!TempOpportunity.Board_Poll_Date__c}')"/>

-Thanks
Ash
Onur KayaOnur Kaya
Hi Ash and James,

I ended up adding actionSupport. So when I update the date fields it reRenders the form and when I click on the generatePDF button right parameteres are being populated.

Thank you both. 
 
<td><apex:inputField id="BegDate" value="{!TempOpportunity.FS_Disbursement_Request_Date__c}" label="" required="true">
                  <apex:actionSupport action="{!FundReportPage}" event="onchange" reRender="block" />
                  </apex:inputField></td>
              <td><apex:inputField id="eEndDate" value="{!TempOpportunity.Board_Poll_Date__c}" label="" required="true">
                  <apex:actionSupport action="{!FundReportPage}" event="onchange" reRender="block" />
              </apex:inputField></td>

 
This was selected as the best answer