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
Mike_M_2Mike_M_2 

Can't Pass visualforce parameter to controller. 5 line example

It's very simple. I need my visualforce page to pass a string literal constant to my controller extension. 
The VF page ...
<apex:page standardController="Opportunity" extensions="OpportunityActualList"  sidebar="false" showHeader="false">

    <apex:form >
        <apex:pageBlock >
            <apex:param name="val" value="abc" />
        </apex:pageBlock>
    </apex:form>
 
</apex:page>

The controller...
public class OpportunityActualList {
public string passValue{get; set;}
    
    public OpportunityActualList(ApexPages.StandardController controller){
    passValue = Apexpages.currentPage().getparameters().get('val');      
    system.debug('passValue:' + passValue);
    }   
}

The debug log shows the value is null.
 
Ajay K DubediAjay K Dubedi
Hi Mike,

Please look the below code :

VF page:

<apex:page standardController="Opportunity" extensions="OpportunityActualList"  sidebar="false" showHeader="false">

    <apex:form >
        <apex:pageBlock >
            <apex:param name="val" value="{!abc}" />
        </apex:pageBlock>
    </apex:form>
 
</apex:page>

- In vf page there is the mistake in row 5 you are missing the {! } expression
Apex class:

public class OpportunityActualList {

    public string passValue{get; set;}
    public string abc{get;set;}
    public OpportunityActualList(ApexPages.StandardController controller){

    passValue = Apexpages.currentPage().getparameters().get('val');     

    system.debug('passValue:' + passValue);

    }  

}

- In class you have to make getter setter of abc also,

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks,
Ajay Dubedi