Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Is there any way to pass the current value of a picklist to a controller via apex:param? I have my apex:param inside of a action:support onChange so when the user selects a picklist option it passes that value to the controller method. I'm able to pass the ID with {!$Component.FIELDID} but is there any way to pass the value for example {!$Component.FIELDID.value}? I'm unable to find much documentation on $Component.

I guess the alternative would be to use an actionFunction? I'm going to try that next but wanted to know if this way was possible.

Thanks!

EDIT : snippet (the inputField is a picklist)

<apex:inputField value="{!thisContact.Degree_Level__c}" id="degreeLevel">
                  <apex:actionSupport event="onchange" 
                            action="{!updateDegreeSelected}" 
                            rerender="program"
                            immediate="true">                      
                        <apex:param name="degreeSelected" assignTo="{!degreeSelected}" value="{!$Component.degreeLevel}"/>
                  </apex:actionSupport>
            </apex:inputField>
share|improve this question
    
Would you please share the markup. apex:ActionSupport would have to go inside of something else. What is that something else? Is it a SelectList, InputField, something else? –  Peter Jan 24 '13 at 16:39
    
Added code snippet. –  Phil B Jan 24 '13 at 16:41
add comment

3 Answers

Unless I'm missing the point of what you're trying to do, the currently selected value is accessible in the field that is bound to your inputField's value attribute.

<apex:actionRegion>
   <apex:inputField value="{!thisContact.Degree_Level__c}" id="degreeLevel">
      <apex:actionSupport event="onchange" 
                            action="{!updateDegreeSelected}" 
                            rerender="program"/>              
   </apex:inputField>
</apex:actionRegion>

EDIT: Removed immediate attribute. Default is false.

So it should be accessible to the controller through thisContact.Degree_Level__c.

So somewhere in your controller you have a property called thisContaact and a method called updateDegreeSelected that look something like this:

public Contact thisContact{get;set;} //here is your contact property
public void updateDegreeSelected(){
//call the thisContact field in here...
    System.debug(thisContact.Degree_Level__c);

}
share|improve this answer
    
I believe its accessible once the form is submitted but not as the user is changing the value of the picklist. –  Phil B Jan 24 '13 at 16:52
1  
I've seen this with partial page refreshes, and used actionRegion to surround the portion of the form to be posted back. I've amended my answer. You need to be careful with actionRegion as anything outside of it will not be posted back to the server. So make sure that everything that does need to get back is inside of it. You can place it anywhere inside of your apex:form tag. –  Peter Jan 27 '13 at 23:25
    
I think you need to remove the immediate="true", so that it defaults to false or change it to immedate="false" otherwise the property in the controller won't be set to the changed value. –  Peter Knolle Jan 27 '13 at 23:52
    
You're right...I looked at that last night, but it didn't sink in. Immediate true means no data passed to controller. Thanks other Peter. :-) –  Peter Jan 28 '13 at 9:42
add comment

I will not prefer apex param.

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_selectList.htm

The select list option and select list visualforce tag is made for the picklist values .Using this in controller we get selected value

share|improve this answer
    
Agree with mohit.the advantage here is that the values also get automatically bonded with the variable in you class –  Shailesh Deshpande Jan 24 '13 at 16:36
    
I am using a selectList. I added a code sample. I want to be able to pass the value the user has selected without submitting the form so I can essentially have a dependent picklist. –  Phil B Jan 24 '13 at 16:42
add comment

You can do something like this -

<apex:inputField value="{!thisContact.Degree_Level__c}" id="degreeLevel" 
 onchange="assignDegreeLevel(this.value)"/>       


 <apex:actionFunction name="assignDegreeLevel" action="{!updateDegreeSelected}" 
   reRender="program" immediate="true">
      <apex:param name="degreeSelected" assignTo="{!degreeSelected}" value=""/>
 </apex:actionFunction>  

It would work..

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.