You need to sign in to do that
Don't have an account?

display selected value on selectList
If a user has made a selection from a selectList, is there a way to display the selected value as the default?
Initially, when the user comes to the page, I have SelectOption set as follows:
options.add(new SelectOption('','-- Please select --')); for (string s : strSundays) { options.add(new SelectOption(s,s)); } return options;
Upon returning to the page for the specified record, I want to show the selected value as the default instead of '-- Please select --'
Here is the code used for the selection list:
VF code:
<apex:selectList multiselect="false" size="1" value="{!workweek}" > <apex:selectOptions value="{!items}" /> </apex:selectList>
Controller class code:
string workweek; public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); List<date> dates = getSundays(); List<string> strSundays = new List<string>(); for (date d: dates) { strSundays.add(string.valueof(d)); } options.add(new SelectOption('','-- Please select --')); for (string s : strSundays) { options.add(new SelectOption(s,s)); } return options; } public string getWorkWeek() { return workweek; } public void setWorkWeek(string workweek) { this.workweek = workweek; }
Thanks.
Take a look at the following blog post. There is code for multiple picklists where I set the selected value.
Dependent Multilevel Selectlists
Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com
the string "workweek" should hold the selected value as you are passing the list values using "item"
All you have to do is to assign the selected value from DB to the property "workweek".