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
BBeairdBBeaird 

Passing selected picklist value to Controller method

How do you pass the currently selected value of a picklist to a controller via apex:param?  I have a picklist where a user selects a value and clicks a button.  I want the value they selected to be passed to my controller method.  I can't seem to find the syntax for getting the value.  Code is below.

 

<apex:pageBlock >
<apex:pageblockSection >

<apex:inputField id="startMode" value="{!Asset.Start_Mode__c}" />

<apex:commandButton  value="Update" action="{!setMachine}" status="myStatus" rerender="thediv">
             <apex:param name="vlsetting" value="'{!$Component.startMode}'"  assignTo="{!vlsettingValue}"/>           
 </apex:commandButton>
 <apex:actionStatus id="myStatus">
            <apex:facet name="start">
            Setting Start Mode
            </apex:facet>
 </apex:actionStatus>

 

 

It seems like it should not be that hard to figure this out, but I can't seem to Google the right keywords.

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.

I am not sure if you are strict to sent the value of picklist using apex:param.

Since you are not using any immediate action on button so you can easily access the binded values into the action method of button defined in controller.

 

<apex:inputField id="startMode" value="{!Asset.Start_Mode__c}" />

<apex:commandButton  value="Update" action="{!setMachine}" status="myStatus" rerender="thediv"/>

 

in controller

public void setMachine() {

   system.debug('Start Mode---' + asset.Start_Mode__c);

}

 

try using this.

 

Regards,

Prafull G.

All Answers

Prafull G.Prafull G.

I am not sure if you are strict to sent the value of picklist using apex:param.

Since you are not using any immediate action on button so you can easily access the binded values into the action method of button defined in controller.

 

<apex:inputField id="startMode" value="{!Asset.Start_Mode__c}" />

<apex:commandButton  value="Update" action="{!setMachine}" status="myStatus" rerender="thediv"/>

 

in controller

public void setMachine() {

   system.debug('Start Mode---' + asset.Start_Mode__c);

}

 

try using this.

 

Regards,

Prafull G.

This was selected as the best answer
BBeairdBBeaird

I think I was confused over the way fields were bound such that the selected value is already available in the controller once the command button is clicked.  Thanks!