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
MevinMevin 

How to retrieve selected picklist value from VF page

Can someone help me on how How to retrieve selected picklist value from VF page??

NikhilNikhil

Is this VF page is using any class(controller) if yes then which type of controller - Custom or Standard or Extenssion

 

Please let us know this so that we can help you.

MevinMevin

Hello,

yes i'm using a controller and a extension.

Note the pickist has custom values; they are not retrieved from any object

NikhilNikhil

Got it

So you are using a Controller  extenssion but you are not binding this picklist with any of the field of that object.

 

So make a property in controller class as 

 

class myclass

{

 

//Your existing code 

 

String PicklistSelectedVal = '';

 

public String getMyPicklistvalue()

{

    return  PicklistSelectedVal;

}

 

public void setMyPicklistvalue(String val)

{

   PicklistSelectedVal = val;

}

 

 

}

 

 

 

IN VF page 

 

<apex:page .....................>

 

 <your tags and code >............

 

<apex:selectList value="{!MyPicklistvalue}" >
      <apex:selectOptions value="{!items}"/>
 </apex:selectList><p/>

 

 

</apex:page>

 

 

Now once user clicks submit you can pick the selcted value from the variable "PicklistSelectedVal "  direct or by using the property  getMyPicklistvalue()

 

Hope this will help you....

 

 

NAPNAP

thanks for your help

I have done this before; it is not returning any value

If I assign the variable PicklistSelectedVal a value at the start; this value is being return instead of the selected value.

You have an idea why the selected value is not being return??

 


 

mattdarnoldmattdarnold

Are you using a multi-select picklist?

 

-- Matt

MevinMevin

Hi matt,

No its a single-select picklist

TehNrdTehNrd

Here is some simplified code that should work. It it does not the issue may be with your items collection and the values. You also say "If I assign the variable PicklistSelectedVal a value at the start", make sure you are doing this in the contructor.

 

 

Controller:
public String picklistValue {get; set;}

Page:
<apex:selectList value="{!picklistValue}" >
<apex:selectOptions value="{!items}"/>
</apex:selectList>

 

 

 

Message Edited by TehNrd on 05-07-2009 11:56 AM
jeffdonthemicjeffdonthemic

Here is some expanded code that may help also: http://blog.jeffdouglas.com/2008/11/25/dependent-multilevel-selectlists/

 

Jeff Douglas

Informa Plc

http://blog.jeffdouglas.com

Govind TalariGovind Talari
Hi mevin, did you find the answer fro the above question even i am facing the same problem!!