I have a Vf page and Controller as below:
<apex:page controller="DropdownDemoController">
<apex:form >
<apex:outputLabel value="Select a Name : "/>
<apex:selectList value="{!selectedAccName}" multiselect="false" size="1">
<apex:selectOptions value="{!accNames}"/>
</apex:selectList><br/><br/>
<apex:outputlink target="_blank" value="apex/Page2?accName={!selectedAccName}">Send</apex:outputlink>
</apex:form>
Controller:
public class DropdownDemoController
{
public List<SelectOption> accNames{get;set;}
public String selectedAccName{get;set;}
public DropdownDemoController()
{
accNames = new List<SelectOption>();
for(Account acc : [SELECT Name FROM Account LIMIT 5])
{
accNames.add(new SelectOption(acc.Name, acc.Name));
}
}
public void submit()
{
System.debug('selectedItem is '+selectedAccName);
}
}
The page displays Account Names in a picklist. User can select an Account Name from the picklist and on clicking the Send link, the selected Account name will be passed to Page2 as a parameter. But it seems the parameter is passed as null instead of actual selected acc name in this case, can you please let me know why and how to correct it.
Thanks.