Skip to main content
added 1345 characters in body; edited tags
Source Link
Samuel De Rycke
  • 9.6k
  • 8
  • 46
  • 73
   <apex:page controller="selectlist">
  <apex:form >
      <apex:selectList value="{!sv}" size="1" rendered="true">
          <apex:selectOptions value="{!value}">         
          </apex:selectOptions>     
      </apex:selectList>  
  </apex:form>
  <apex:outputPanel id="output">
      <apex:outputLabel value="{!Iddisplay}">
      </apex:outputLabel>
  </apex:outputPanel>
 
</apex:page>


-------------------------- controller--------------------------
public class selectlist
 {
    public String sv { get; set; }
    public String getIddisplay() 
    {
        return null;
    }


    public List<SelectOption> getValue()
     {
         List<SelectOption> option = new List<SelectOption>();
         option.add(new selectoption('none','---Select--'));
         for(Account ac: [Select Id,name From Account limit 5])
         {
             option.add(new SelectOption(ac.id,ac.name));
         
         }
         return option;      
    }
}

update: This way I tried and succeed but...

<apex:page controller="SelectList3">
    <apex:form >
        <apex:selectList value="{!slv}" size="1">
            <apex:actionSupport event="onchange" reRender="out" />
            <apex:selectOptions value="{!value}">                     
            </apex:selectOptions>               
        </apex:selectList>
    </apex:form>
    <apex:outputPanel id="out">
        <apex:outputText value="{!slv}">
        
        </apex:outputText>
    
    </apex:outputPanel>
  
</apex:page>

Controller:

public with sharing class SelectList3 
{
    public list<selectoption> getValue()
     {
        list<SelectOption> ls= new list<SelectOption>();
        for(Contact acc:[select id, name from Contact])
        {
            ls.add(new SelectOption(acc.id,acc.name));
        }
        return ls;
    }

    public String slv { get; set; }
    
}

Now my question is how to pass the select value to a method..and fetch the value of record details with that id...Find detailed explination below..

In above code with the slv will return "id" of the selected value... Now using this Id I want to get related values of Account[ name etc..]

   <apex:page controller="selectlist">
  <apex:form >
      <apex:selectList value="{!sv}" size="1" rendered="true">
          <apex:selectOptions value="{!value}">         
          </apex:selectOptions>     
      </apex:selectList>  
  </apex:form>
  <apex:outputPanel id="output">
      <apex:outputLabel value="{!Iddisplay}">
      </apex:outputLabel>
  </apex:outputPanel>
 
</apex:page>


-------------------------- controller--------------------------
public class selectlist
 {
    public String sv { get; set; }
    public String getIddisplay() 
    {
        return null;
    }


    public List<SelectOption> getValue()
     {
         List<SelectOption> option = new List<SelectOption>();
         option.add(new selectoption('none','---Select--'));
         for(Account ac: [Select Id,name From Account limit 5])
         {
             option.add(new SelectOption(ac.id,ac.name));
         
         }
         return option;      
    }


    
}
   <apex:page controller="selectlist">
  <apex:form >
      <apex:selectList value="{!sv}" size="1" rendered="true">
          <apex:selectOptions value="{!value}">         
          </apex:selectOptions>     
      </apex:selectList>  
  </apex:form>
  <apex:outputPanel id="output">
      <apex:outputLabel value="{!Iddisplay}">
      </apex:outputLabel>
  </apex:outputPanel>
 
</apex:page>


-------------------------- controller--------------------------
public class selectlist
 {
    public String sv { get; set; }
    public String getIddisplay() 
    {
        return null;
    }


    public List<SelectOption> getValue()
     {
         List<SelectOption> option = new List<SelectOption>();
         option.add(new selectoption('none','---Select--'));
         for(Account ac: [Select Id,name From Account limit 5])
         {
             option.add(new SelectOption(ac.id,ac.name));
         
         }
         return option;      
    }
}

update: This way I tried and succeed but...

<apex:page controller="SelectList3">
    <apex:form >
        <apex:selectList value="{!slv}" size="1">
            <apex:actionSupport event="onchange" reRender="out" />
            <apex:selectOptions value="{!value}">                     
            </apex:selectOptions>               
        </apex:selectList>
    </apex:form>
    <apex:outputPanel id="out">
        <apex:outputText value="{!slv}">
        
        </apex:outputText>
    
    </apex:outputPanel>
  
</apex:page>

Controller:

public with sharing class SelectList3 
{
    public list<selectoption> getValue()
     {
        list<SelectOption> ls= new list<SelectOption>();
        for(Contact acc:[select id, name from Contact])
        {
            ls.add(new SelectOption(acc.id,acc.name));
        }
        return ls;
    }

    public String slv { get; set; }
    
}

Now my question is how to pass the select value to a method..and fetch the value of record details with that id...Find detailed explination below..

In above code with the slv will return "id" of the selected value... Now using this Id I want to get related values of Account[ name etc..]

Source Link
vamshi
  • 81
  • 2
  • 4

Select option out put

This is my problem... I have a select list.. When I select the value, according to the value.. the id should be displayed..I done some part remaining part I struck. please find the code below.

   <apex:page controller="selectlist">
  <apex:form >
      <apex:selectList value="{!sv}" size="1" rendered="true">
          <apex:selectOptions value="{!value}">         
          </apex:selectOptions>     
      </apex:selectList>  
  </apex:form>
  <apex:outputPanel id="output">
      <apex:outputLabel value="{!Iddisplay}">
      </apex:outputLabel>
  </apex:outputPanel>
 
</apex:page>


-------------------------- controller--------------------------
public class selectlist
 {
    public String sv { get; set; }
    public String getIddisplay() 
    {
        return null;
    }


    public List<SelectOption> getValue()
     {
         List<SelectOption> option = new List<SelectOption>();
         option.add(new selectoption('none','---Select--'));
         for(Account ac: [Select Id,name From Account limit 5])
         {
             option.add(new SelectOption(ac.id,ac.name));
         
         }
         return option;      
    }


    
}