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
rosscorossco 

How to Pass selectlist value to another Visualforce Page

Hi

 

I am struggling to pass the value of a selectlist (single) from one visualforce page to another.  I can pass the eventid but not the Account ID selected:-

 

Here is my VF page (controller follows):-

<apex:page Controller="TrainingConfirmation" sidebar="false"  showheader="false">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Training Confirmation - Select Company" columns="1">
      <apex:pageblocksectionItem >
                  <apex:selectList value="{!accountId}" size="1" id="accountId">
              <apex:selectOptions value="{!accounts}"/>
          </apex:selectList>
      </apex:pageblocksectionItem>    
                            </apex:pageblocksection>           
  </apex:pageblock>

<apex:outputlink value="/apex/atrainingfconfirmation2"> Click here to Generate Training Confirmation <apex:param name="company" value="{!accountId}"/> <apex:param name="eventid" value="{!event.id}"/></apex:outputlink>
</apex:form>
</apex:page>

 

Here is my Controller:

public class TrainingConfirmation{

    private Account account;
    public List<CQS_Delegate__c> delegate = new List<CQS_Delegate__c>();
    
    private CQS_Event__c event;
    public Id eventid;
     
    
    public TrainingConfirmation(){
        eventid='a0FR0000006pk4o';
        system.debug('delegate id: '+accountid);
        event= [SELECT Id, Name,Start_Date__c,Venue__r.Name,Venue__r.Address__c FROM CQS_Event__c WHERE Id = :eventid limit 1];  

        
    }
            
    public CQS_Event__c getevent(){
        return event;
    }
          
   public List<CQS_Delegate__c> getdelegates(){
        delegate = [SELECT Contact__c,No_of_Delegates__c,Contact__r.Name,Dietary_Requirement__c,Account__r.Name,Payment_Status__c from CQS_Delegate__c WHERE Event__c =:eventid ];
             return delegate;
    }
    
    
    public ID AccountID {get; set;}
    
    public List<SelectOption> accounts    {  
    get    {
     if (accounts == null) {
        accounts = new List<SelectOption>();
        List<Account> citylist = new List<Account>();  
        citylist = [Select Id, Name from Account where ID IN (Select Account__c from CQS_Delegate__C where Event__C =:eventid) ];  
        for (Integer j=0;j<citylist.size();j++)  
        {      
        accounts.add(new SelectOption(citylist[j].ID,citylist[j].Name));  
        }  
    }
   return accounts;
   }
    set;
}

}

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

The problem is that the outputlink is rendered with the initial value of accountId - i.e. empty.

 

The fact that the user selects a value from the selectlist won't have any impact on accountId unless you submit the form back.

 

There's a number of different ways to solve this, but a command link is a straightforward option:

 

Page:

 

 

<apex:commandlink value="Click Here" action="{!genConfirm}"/>

 

Controller:

 

 

public PageReference genConfirm()
{
   PageReference result=new PageReference('/apex/atrainingfconfirmation2');  
                  // or possibly Page.atrainingfconfirmation2;
   result.getParameters().put('eventid', event.id);
   result.getParameters().put('company', accountId);

   return result;
}