+ Start a Discussion

How to display pageblocksection on selecting a value from the picklist?

* By default all the pageblocks should be in hide.

* On chaning picklist value corresponding page block section should display remaining should hide

   If, I select india, only india pageblock section should display

   If, I select Us, only Us pageblock section should display

* I did it with command buttons

<apex:page controller="coun">
<apex:form >

<apex:commandButton value="India" action="{!india}" reRender="India,Us,Uk"/>
<apex:commandButton value="Us" action="{!us}" reRender="India,Us,Uk"/>
<apex:commandButton value="Uk" action="{!uk}" reRender="India,Us,Uk"/>

<apex:pageBlock >

<apex:outputPanel id="India">
<apex:pageBlockSection title="India" rendered="{!mhide}">

<apex:outputpanel id="Us">
<apex:pageBlockSection title="US" rendered="{!m1hide}">

<apex:outputpanel id="Uk">
<apex:pageBlockSection title="UK" rendered="{!m2hide}">





public class coun {

    public Boolean hide = false;
    public Boolean hide1 = false;
    public Boolean hide2 = false;
    public void setMhide(Boolean b) {
    this.hide = b;
    public Boolean getMhide() {
    return this.hide;
    }//Passing input dynamically through another method
    public Boolean getM1hide() {
        return this.hide2;
    public void setM1hide(Boolean b) {
      this.hide2 = b; 
    public Boolean getM2hide() {
        return this.hide1;
    public void setM2hide(Boolean b) {
        this.hide1 = b;
   public PageReference india() {
        return null;
//displaying only india information and hiding other information
     public PageReference us() {
        return null;
    public PageReference uk() {
        return null;

 *While trying with picklist, I got partial result.

*How to retrieve selected picklist value form vf to controller class and compare?






I have similar code which might be useful to you.

Use Select option Component for displaying the pick list.

Use Property variable to get the selected value from VFP to Apex class and Implement required logic as you needed


<apex:pageBlockSectionItem >
  <apex:outputLabel value="select vendor details"/>
    <apex:selectList size="1"  value="{!det}" >
      <apex:selectOptions value="{!props}" id="thepageid"/>
      <apex:actionSupport event="onchange" id="lm" reRender="loc"/>

 Place above code in Output panel and page block section and render page block section as when you required



Sample code for Apex to add the values to Pick list.


 //method to get rlist
      public List<SelectOption> getprops() //detprops for getting names in picklist
             List<SelectOption> opt = new List<SelectOption>();
              opt.add(new SelectOption('none','NONE'));
              opt.add(new SelectOption('contact','CONTACT'));
              opt.add(new SelectOption('location','LOCATION'));
              opt.add(new SelectOption('both','BOTH'));
             return opt;

Above code might be helpful to you.


Thanks for Reply,


My question is how to dispaly pageblock sections on vfp based on the picklist value selection.




You can use Action support component for this

Use Below code to call controller action when a pick list value is selected and do the required operation in that controller

(setting render attribute to true or false as you required ) and ReRender the required sections


<apex:outputPanel id="op1">
          <apex:selectList size="5" value="{!vnames}">
           <apex:selectOptions value="{!names}" id="so1"/>
            <apex:actionSupport event="onchange" reRender="op2,thepageid,lm,tmp,con,bt" action="{!listmethod}" />


I have implemented this exactly same with help of above code and working fine, am able to render the Page Blocks based ion selection of Pick list values.

As per above code sample you gave, you have good enough knowledge to implement this.

balaji malemarpurambalaji malemarpuram


1)First of all declare a propery for holding selected picklist value in controller.

2)In selectlist tag use "onchange" event  to use in actionfunction

3)In actionfunctionfunction use name of function in onchange event and then specify the method in action attribute.

4)In that method you have to set renderings for pageblocksections.



In page


<apex:actionfunction name="fun" action="{!processMethod}"/>


<apex:selectlist value="{!selectedpicklistvalue}" onchange="fun();">

        <apex:selectOptions value="{!values}"/>



In controller


In constructor set the false to all pageblocksections by defalse.


In Processmethod

public void processmethod(){