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
Scott.MScott.M 

Maintain State Across Visualforce Pages

Hi,

 

I'm having some trouble maintaining state across multiple visualforce pages like in the wizard example. I'm using the same controller class on both visualforce pages but when I call the function that displays the next visualforce page in the wizard it creates a new controller instead of using the existing one. Any ideas why that might be? 

 

 

 

 

TehNrdTehNrd
Are you using setRedirect(true); ? If so, I think this causes a new class to be instantiated.
Message Edited by TehNrd on 02-27-2009 01:26 PM
Scott.MScott.M

No i'm not, it may be another issue :)

 

Here's the code:

 

 

public class ContractInvoiceController { public class SelectWrapper{ public Boolean selected {get; set;} public Contract_Line_Item__c line_item {get; set;} public SelectWrapper(Contract_Line_Item__c li) { this.line_item = li; this.selected = false; } } public Contract contract {get; set;} public Boolean PDF {get; set;} public Contract_Line_Item__c[] UnBilled {get; set;} public Contract_Line_Item__c[] BillList {get; set;} public SelectWrapper[] SelectOptions {get; set;} public DateTime InvoiceDate; public String mode; public ContractInvoiceController() { Id contract_id = System.currentPageReference().getParameters().get('id'); this.contract = [SELECT Id, Invoice_Address__c, ShippingCountry, ShippingState, ShippingCity, ShippingPostalCode, ShippingStreet, Ship_Via__c, Tracker_Number__c, Contract_Number__c, Customer_P_O__c, Rep__r.Name, Status FROM Contract WHERE Id =: contract_id]; this.InvoiceDate = System.now(); this.UnBilled = [SELECT Id, Quantity__c, Unit__c, Description__c, Unit_Price__c, Total__c, GST__c, PST__c FROM Contract_Line_Item__c WHERE Contract__c =: contract_id AND Invoiced__c = false]; if(this.SelectOptions == null) { this.SelectOptions = new List<SelectWrapper>(); for(Contract_Line_Item__c li: this.UnBilled) { this.SelectOptions.add(new SelectWrapper(li)); } } this.mode = System.currentPageReference().getParameters().get('mode'); if(this.mode == 'complete') { this.BillList = this.UnBilled; } } public PageReference ExecuteInvoice() { this.BillList = new List<Contract_Line_Item__c>(); for(SelectWrapper wrapper: SelectOptions) { if(wrapper.selected == true) { this.BillList.add(wrapper.line_item); } } PageReference pageRef = Page.Invoice; pageRef.setRedirect(false); return pageRef; } public String getInvoiceDateStr() { return InvoiceDate.format('MMMM dd, yyyy'); } }

 

 

 

dchasmandchasman
Can you also post the 2 pages in question?
Scott.MScott.M

Sure :) here are the pages

 

 Page.SelectInvoiceItems

 

<apex:page controller="ContractInvoiceController" > <apex:form > <apex:pageBlock title="Select the line items to invoice" > <apex:pageBlockButtons > <apex:commandButton action="{!ExecuteInvoice}" value="Invoice" /> </apex:pageBlockButtons> <apex:pageBlockTable value="{!SelectOptions}" var="wrapper"> <apex:column > <apex:inputCheckbox value="{!wrapper.selected}" /> </apex:column> <apex:column > <apex:outputField value="{!wrapper.line_item.Quantity__c}" /> </apex:column> <apex:column > <apex:outputField value="{!wrapper.line_item.Unit__c}" /> </apex:column> <apex:column > <apex:outputField value="{!wrapper.line_item.Description__c}" /> </apex:column> <apex:column > <apex:outputField value="{!wrapper.line_item.Total__c}" /> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

 

Page.Invoice

 

 

<apex:page controller="ContractInvoiceController" sideBar="false" showHeader="false" standardstylesheets="false" renderAs="pdf"> <apex:stylesheet value="{!$Resource.invoicepdf}" /> <img src="{!$Resource.letterhead}" style="position: fixed; left: 0.27cm; top:0.25cm; z-index:-1" width="21cm"> <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> <table class="invoicetable"> <tr> <td colspan="2" class="alignright"><strong>INVOICE</strong></td> </tr> <tr> <td colspan="2">&nbsp;</td> </tr> <tr> <td colspan="2" class="alignright"> <table class="datetable"> <tr> <td>Date</td> <td>Invoice #</td> </tr> <tr> <td><apex:outputText value="{!InvoiceDateStr}" /></td> <td>STG-0001</td> </tr> </table> </td> </tr> <tr> <td colspan="2" >&nbsp;</td> </tr> <tr> <td> <table class="invoiceto" > <tr> <td class="header">Invoice To</td> </tr> <tr> <td class="address"> <apex:outputText value="{!contract.Invoice_Address__c}" /> </td> </tr> </table> </td> <td> <table class="shipto"> <tr> <td class="header">Ship To</td> </tr> <tr> <td class="address"> <apex:outputText value="{!contract.ShippingStreet}" /><br /> <apex:outputText value="{!contract.ShippingCity}" /><br /> <apex:outputText value="{!contract.ShippingState}" /><br /> <apex:outputText value="{!contract.ShippingCountry}" /><br /> <apex:outputText value="{!contract.ShippingPostalCode}" /> </td> </tr> </table> </td> </tr> <tr> <td colspan="2">&nbsp;</td> </tr> <tr> <td colspan="2"> <table class="borderedtable" width="100%"> <tr> <td>PO #</td> <td>Terms</td> <td>Rep</td> <td>Ship Via</td> <td>Tracker #</td> <td>F.O.B</td> <td>Contract #</td> </tr> <tr> <td></td> <td>Net 30</td> <td><apex:outputText value="{!contract.Rep__r.Name}" /></td> <td><apex:outputText value="{!contract.Ship_Via__c}" /></td> <td><apex:outputText value="{!contract.Tracker_Number__c}" /></td> <td>N/A</td> <td><apex:outputText value="{!contract.Contract_Number__c}" /></td> </tr> <tr> <td>Quantity</td> <td>Item</td> <td colspan="3">Description</td> <td>Price Each</td> <td>Amount</td> </tr> <apex:repeat value="{!BillList}" var="line_item"> <tr> <td class="centertd"><apex:outputField value="{!line_item.Quantity__c}" /></td> <td class="centertd">1</td> <td class="centertd" colspan="3"><apex:outputField value="{!line_item.Description__c}" /></td> <td class="centertd"><apex:outputField value="{!line_item.Unit_Price__c}" /></td> <td class="centertd"><apex:outputField value="{!line_item.Total__c}" /></td> </tr> </apex:repeat> <tr> <td class="centertd"></td> <td class="centertd"></td> <td class="centertd" colspan="3"> Sales Tax Summary: </td> <td class="centertd"></td> <td class="centertd"></td> </tr> <tr> <td class="centertd"></td> <td class="centertd"></td> <td class="centertd" colspan="3"> GST on Sales @ 5%: </td> <td class="centertd"></td> <td class="centertd">CAD 1,0000</td> </tr> <tr> <td class="centertd"></td> <td class="centertd"></td> <td class="centertd" colspan="3"> PST on Sales @ 8%: </td> <td class="centertd"></td> <td class="centertd">CAD 1,0000</td> </tr> <tr> <td class='total1' colspan="5"> <td class='total2' align="left">TOTAL </td> <td class='total3' align="right">CAD 1,0000</td> </tr> </table> </td> </tr> </table> </apex:page>

 

 

 

 

 

Scott.MScott.M

Any thoughts on what might be causing this? I ran into a similar problem generating a pdf with post parameters in code that used to work. I saw some threads about there being an issue with http parameters in pdf generation. I suspect it might be related with the difference being the use of the 'getContent' function.

 

TomSnyderTomSnyder

For it to work for me i had to reference the page like so...

 

PageReference mp = Page.MyPage;

PageReference p = new PageReference('https://'+ApexPages.CurrentPage().getHeaders().get('Host')+mp.getUrl()+'?id='+userId);

jhugjhug

Have you tried keeping the apex:page tag element standardController="Contract" and using the extensions="ContractInvoiceController" tag element?

 

Page tag as follows:

 

 

<apex:page standardController="Contract" extensions="ContractInvoiceController>
...
</apex:page>

 

 

 

Class constructor as follows:

 

 

public ContractInvoiceController(ApexPages.StandardController controller) {
Contract contract = (Contract)controller.getRecord();
...
}