+ Start a Discussion
skyfall007skyfall007 

Passing List from VF Page to another VF Page

Hi,

 

I have a controller class and a VF page that display a list of records from which a user can select any number of records. Once a user check marks the records, they are displayed in second section of VF page.

 

Now again on second VF page (PDF page), I want to display the list again with extra information. But that list is not getting carried forward from one page to another.

 

Please suggest me as to what shall be done.

 

Thanks

skyfall007skyfall007

Hi,

 

Thanks for the reply. I did read the post earlier but couldn't fix my issue.

 

I have followed this link to get list of records and when user selects the records, they get stored in a list.

 

If I write System.debug() to print the selected list in constructor, it prints.... () ....empty wrapperclass list.

 

Why I am not able to fetch the selectedList from another method into the constructor?

Ritesh AswaneyRitesh Aswaney

It seems like a wizard. Sharing the same controller between the two pages simplifies things quite a bit - are you using a common controller?

This post resolves an issue very simiar to yours - have a read.

http://boards.developerforce.com/t5/Visualforce-Development/Two-VF-pages-sharing-one-controller-data-not-available-in-second/td-p/436507

skyfall007skyfall007

I am using the same controller. I am still not able to fix the issue.

 

public class ControllerClass {
	public String currentPageId{get;set;}
	public List<orderWrapper> orderListWrapper{get;set;}
	public Order__c orderObj{get;set;}
    public String parId{get;set;}
    public List<Order__c> selectedOrders{get;set;}
    public List<MultiOrderWrapperClass> multiOrderList{get;set;}
    
	public ControllerClass(){
	currentPageId = ApexPages.currentPage().getParameters().get('id');
	orderListWrapper = new List<orderWrapper>();
    selectedOrders = new List<Order__c>();
    multiOrderList = new List<MultiOrderWrapperClass>();
    } 
	
	public List<orderWrapper> getOrders(){
        for(Order__c o : [Select Name From Order where *somecondition*])
                orderListWrapper.add(new orderWrapper(o));
        return orderListWrapper;
	}
	public PageReference getSelected(){
        selectedOrders.clear();    
        for(OrderWrapper ordWrapper : orderListWrapper)
        if(ordWrapper.selected == true)
        selectedOrders.add(ordWrapper.ord);
        return null;
	}
	
public PageReference init(){
		multiOrderList = new List<MultiOrderWrapperClass>();
        Order__c orderObj = [Select Name from Order__c where id=: currentPageId];
        List<Id> selectedOrderIds = new List<Id>();
        for(Integer i=0; i<selectedOrders.size();i++ ){selectedOrderIds.add(selectedOrders[i].id);}
        for(Order obj : [Select Name from Order where id IN : selectedOrderIds]){
									
        		MultiOrderWrapperClass mOrderObj = new MultiOrderWrapperClass(obj);
            	multiOrderList.add(mOrderObj);
        }
    
        PageReference pdf = Page.SecondVFPage;
        pdf.getParameters().put('id',currentPageId);
		Datetime temp = Datetime.newInstance(datetime.now().year(), datetime.now().month(),datetime.now().day());
        Attachment attach = new Attachment();
        blob body;
       try
        {
            body = pdf.getcontent();
        }
        catch (visualforceexception e)
        {
            body = blob.valueof('some text');    // This is used to pass unit test criteria
        }
       attach.body = body;
        attach.name = 'Name'; 
        attach.isprivate = false;
        attach.parentid = currentPageId;
        insert attach;
        return new PageReference('/'+currentPageId);
        
    
	}
	public PageReference cancel(){
	return new PageReference('/'+currentPageId);

	}
	public class OrderWrapper{
		public Order__c ord{get; set;}
		public Boolean selected {get; set;}
		public orderWrapper(Order o){
            ord = o;
            selected = false;
		}
	}
	public class MultiOrderWrapperClass{
		public String name{get;set;}
		public MultiOrderWrapperClass(Order Obj){
		this.name = Obj.Name;
		}
	}
}



 



First VF Page
<apex:page controller="Creative_MultipleOrderLine" sidebar="false"> 
	<apex:form >
		<apex:pageBlock title="Parent : {!parId}">
 			<apex:pageBlockButtons >
    			<apex:commandButton value="Generate Order" action="{!init}"/>
    			<apex:commandButton value="Cancel" action="{!cancel}"/>
 			</apex:pageBlockButtons>
 			<apex:pageBlockSection title="Related Order List">
 			
 			 
 				<apex:dataTable value="{!orders}" var="o" columnswidth="50px,50px" cellpadding="4" border="1">
 				<apex:column >
 				<apex:facet name="header">
 				<!--<apex:inputCheckbox onclick="{!selectedOrders}">
 					  <apex:actionSupport event="onclick" action="{!getSelected}" onsubmit="checkAll(this)" rerender="Selected_ORD"/>
				</apex:inputCheckbox>-->
				</apex:facet>
			 	<apex:inputCheckbox value="{!o.selected}" id="checkedone">
					  <apex:actionSupport event="onclick" action="{!getSelected}" rerender="Selected_ORD"/>
				</apex:inputCheckbox>
				</apex:column>
				<apex:column headervalue="Order ID" value="{!o.ord.Name}" />
				</apex:dataTable>
			</apex:pageBlockSection>
			<apex:pageBlockSection Title="Selected Order List" id="Selected_ORD">
			<apex:dataTable value="{!SelectedOrders}" var="s" columnswidth="50px,50px" cellpadding="4" border="1">
			<apex:column headervalue="Order ID" value="{!s.Name}" />
			</apex:dataTable> 
			</apex:pageBlockSection>
			
		</apex:pageBlock>
	</apex:form>
</apex:page>

SecondVF Page
<apex:page controller="Creative_MultipleOrderLine" showheader="false" renderas="pdf"> 
View {!multiOrderList} View
</apex:page