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
bcgbcg 

Page render on basis of picklist values

Hello,

 

anyone plz help me.

 

I want to render the pageblocksection, when i select values from picklist fromanother pageblocksection on same page then secong page block section rendered and shows the values accroding to selected values.

 

How can i solve this.. anyone knows plz help me......

myluckymylucky

you can use <apex:actionSupport> componenet after writing the taking the picklist value.

 

In the actionSupport tag you have to mention the attributes as:

 

<apex:actionSupport event="onchange" rerender="pageblocksectionid">

 

If you want to perform any action after selecting the picklist value you can use action attribute also.

 

Hope this will work for your requirement....

bcgbcg

Thanks Dear,

 

Will you plz give me any example code of my problem. actually am new to salesforce and i don't know how to implement it.

myluckymylucky

i am sending some example code on picklist. if you change the first picklist value then only the second picklist values shown based on the first picklst values.

 

here is the some code:

Apex class:

 

public class Detailsclass    
{
 public string VendorValue{get;set;}
 public string DetailValue{get;set;}
 
 public boolean contactvalue{get;set;}
 public boolean locationvalue{get;set;}
 
 public list<Vendor__c> Vendorlist {get;set;}
 public list<Contact__c> Contactlist {get;set;}
 public list<Location__c> Locationlist {get;set;}
 public Detailsclass()
 {
  Vendorlist = [select Vendor_Name__c, Fed_Tax_ID__c, Duns_Number__c from Vendor__c ];
   }
  
 public list<SelectOption> getVendorNames()
 {
  list<SelectOption> opt=new list<SelectOption>();
  for(integer i=0;i<Vendorlist.size();i++)
  opt.add(new SelectOption(Vendorlist[i].id,Vendorlist[i].Vendor_Name__c));
    
  return opt;
 }
 
 public list<SelectOption> getOptions()
 {
  list<SelectOption> opt = new list<SelectOption>();
  
  if(Contactlist.size()>0 && Locationlist.size()>0)
  opt.add(new SelectOption('both','Both'));
  
  if(Contactlist.size()>0)
   opt.add(new SelectOption('contact','Contact'));
  
  if(Locationlist.size()>0)
   opt.add(new SelectOption('location','Location'));
  
   opt.add(new SelectOption('none','None'));
  
  return opt;
 }
 
  public void lists()
 {
  DetailValue = 'none';
  
  contactvalue = true;
  locationvalue = true;
  
  Contactlist = [select Phone_Number__c, Fax_Number__c, Email_Id__c from Contact__c where vendor__c =: VendorValue ];
  Locationlist = [select City__c, State__c, Zip_Code__c from Location__c where vendor__c =: VendorValue ]; 
  
  if(Contactlist.isEmpty())
   contactvalue = false;
  if(Locationlist.isEmpty())
   locationvalue = false;
 
 } 
 
}

 

And the Visualforce page is like:

<apex:page controller="Detailsclass">
  <apex:form >
     <apex:pageBlock >
        <apex:actionRegion >
        
        <apex:pageBlockSection columns="1" title="Vendor Information">
        <apex:outputPanel >
        <apex:selectList id="slvpage" size="1" value="{!VendorValue}"> 
              <apex:selectOptions value="{!VendorNames}"/>
              <apex:actionSupport event="onchange" reRender="DetailValuepage,DetailValueppage,conpage,locpage,bothpage"  action="{!lists}"/>
        </apex:selectList>  
        </apex:outputPanel>
        </apex:pageBlockSection> 
      
        <apex:outputPanel id="DetailValuepage">
        <apex:pageBlockSection columns="1" title="Select Any Detail" id="DetailValueppage" rendered="{!( VendorValue != null && VendorValue != '') && (contactvalue == true || locationvalue == true)}">
        <apex:selectList size="1" value="{!DetailValue}"> 
            <apex:selectOptions value="{!options}"></apex:selectOptions>
            <apex:actionSupport event="onchange" reRender="conpage,locpage,bothpage"/>
        </apex:selectList>
        </apex:pageBlockSection>
        <apex:pageBlockSection id="pbsDetailValuepage1" title="Values not available" rendered="{!( VendorValue != null && VendorValue != '') && (contactvalue == false && locationvalue == false)}">
        Contacts and Locations are not available for the given vendor details.
        </apex:pageBlockSection>
        <apex:pageBlockSection id="pbsDetailValuepage2" title="Location Values not available" rendered="{!( VendorValue != null && VendorValue != '') && (contactvalue == true && locationvalue == false)}">
        Locations are not available for the given vendor details.
        </apex:pageBlockSection>
        <apex:pageBlockSection id="pbsDetailValuepage3" title="Contact Values not available" rendered="{!( VendorValue != null && VendorValue != '') && (contactvalue == false && locationvalue == true)}">
        Contacts are not available for the given vendor details.
        </apex:pageBlockSection>
        
        </apex:outputPanel>
              
        <apex:outputPanel id="conpage">
        <apex:pageBlockSection title="Contacts Information" id="Cbpage" rendered="{!(DetailValue = 'contact') && (contactvalue == true)}">
           <apex:pageBlockTable value="{!Contactlist}" var="cval">
              <apex:column value="{!cval.Phone_Number__c}"/>
              <apex:column value="{!cval.Fax_Number__c}"/>
              <apex:column value="{!cval.Email_Id__c}"/>
           </apex:pageBlockTable>
        </apex:pageBlockSection>
        </apex:outputPanel>
        
        <apex:outputPanel id="locpage">
        <apex:pageBlockSection title="Location Information" id="Lbpage" rendered="{!(DetailValue = 'location') && (locationvalue == true)}">
           <apex:pageBlockTable value="{!Locationlist}" var="lval">
              <apex:column value="{!lval.City__c}"/>
              <apex:column value="{!lval.State__c}"/>
              <apex:column value="{!lval.Zip_Code__c}"/>
           </apex:pageBlockTable>
        </apex:pageBlockSection> 
        </apex:outputPanel>
           
    <apex:outputPanel id="bothpage">
             <apex:pageBlockSection title="Contacts Information" id="Cpage" rendered="{!(DetailValue = 'both')&& (contactvalue == true)}">
              <apex:pageBlockTable value="{!Contactlist}" var="cval">
              <apex:column value="{!cval.Phone_Number__c}"/>
              <apex:column value="{!cval.Fax_Number__c}"/>
              <apex:column value="{!cval.Email_Id__c}"/>
           </apex:pageBlockTable>
        </apex:pageBlockSection>
         <apex:pageBlockSection title="Location Information" id="Lpage" rendered="{!(DetailValue = 'both') && (locationvalue == true)}">
           <apex:pageBlockTable value="{!Locationlist}" var="lval">
              <apex:column value="{!lval.City__c}"/>
              <apex:column value="{!lval.State__c}"/>
              <apex:column value="{!lval.Zip_Code__c}"/>
           </apex:pageBlockTable>
        </apex:pageBlockSection> 
        </apex:outputPanel> 
        
     </apex:actionRegion>
     </apex:pageBlock>
  </apex:form>
</apex:page>

 

 

you can verify the code with your code. And this code work based on the values in the object defined previously.

 

 

Hoping that this code will helps you....................

 

bcgbcg

Thanks for this dear, But my problem is not like that. I have two picklist i.e. Admission Criteria & Admission Process and in both the picklists i have two values. i want when i select one value from first picklist and second value from another picklist then according to selected values it display the PageBlockSection and values of pageblocksection.

Am sending you code please check this if you understand my problem.

 

 Controller:

 

public class Student { 
    public String getAccts() {
        return null;
    }
    
   public String getAdm() {
        return null;
    }
    
  public List<Student__c> getStudent() 
  {
  return [SELECT Name,University_Roll_No__c,Student_Name__c, Roll_No__c FROM Student__c];    
  }
  }

 

 

Apex Page:

 

<apex:page controller="Student" sidebar="false" extensions="Admission">
<apex:form>
<script> 
       
    function listFunction(variable)
    {
    
        var list = variable.value;
       

        if(list == 'Re-Admission')
        {
            document.getElementById('idSpan').style.display = 'block';
                   
        }
        else 
        {
            if (list == 'New Admission')
           document.getElementById('idSpan1').style.display = 'block';
              
        else
        {
            document.getElementById('idSpan1').style.display = 'none';
        }
        }
        }
   
    </script>   

<apex:pageBlock title="Admission process">
<apex:pageBlockSection title="Admission">
<apex:inputField value="{!adm.Admission_Process__c}" onclick="listFunction(this);" />
<apex:inputField value="{!adm.Admission_Criteria__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<span id="idSpan" style = "display:none">
<apex:pageBlock >
<apex:pageBlockSection title="Re-Admission" id="pageblocksec">
<apex:inputField value="{!student.Form_No__c}"/>
<apex:inputField value="{!adm.Session__c}"/>
<apex:inputField value="{!student.Student_Name__c}"/>
<apex:inputField value="{!adm.Registartion_ID__c}"/>
<apex:inputField value="{!student.Gender__c}"/>
<apex:inputField value="{!student.Father_Name__c}"/>
<apex:inputField value="{!student.Mother_Name__c}"/>
<apex:inputField value="{!student.Address__c}"/>
<apex:inputField value="{!student.Course__c}"/>
<apex:inputField value="{!student.Class__c}"/>
<apex:inputField value="{!student.Phone_Number__c}"/>
<apex:inputField value="{!student.Hobbies__c}"/>
<apex:inputField value="{!student.Hostel_Service__c}"/>
<apex:inputField value="{!student.Transport_Service__c}"/>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!accts}" var="a" id="table"> 
<apex:facet name="footer">
<apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error"/>
</apex:facet>
<apex:column headerValue="Class Name">
<apex:inputField value="{!a.Class_Name__c}"/>
</apex:column>
<apex:column headerValue="Board/University">
<apex:inputField value="{!a.Session__c}"/>
</apex:column>
<apex:column headerValue="Percentage">
<apex:inputField value="{!a.Percentage__c}"/>
</apex:column>
<apex:column headerValue="Passing Year">
<apex:inputField value="{!a.Passing_Year__c}"/>
</apex:column>
</apex:pageBlockTable>
<center><br/><br/>
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</center>
</apex:pageBlock>
</span>
<span id="idSpan1" style = "display:none">
<apex:pageBlock >
<apex:pageBlockSection title="New Admission" id="pageblocksec1">
<apex:inputField value="{!student.Form_No__c}"/>
<apex:inputField value="{!adm.Registartion_ID__c}"/>
<apex:inputField value="{!adm.Session__c}"/>
<apex:inputField value="{!student.Entrance_Exam_Roll_No__c}"/>
<apex:inputField value="{!student.Marks_Obtained__c}"/>
<apex:inputField value="{!student.Rank__c}"/>
<apex:inputField value="{!student.Student_Name__c}"/>
<apex:inputField value="{!student.Gender__c}"/>
<apex:inputField value="{!student.Father_Name__c}"/>
<apex:inputField value="{!student.Mother_Name__c}"/>
<apex:inputField value="{!student.Address__c}"/>
<apex:inputField value="{!student.Course__c}"/>
<apex:inputField value="{!student.Class__c}"/>
<apex:inputField value="{!student.Phone_Number__c}"/>
<apex:inputField value="{!student.Hobbies__c}"/>
<apex:inputField value="{!student.Hostel_Service__c}"/>
<apex:inputField value="{!student.Transport_Service__c}"/>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!accts}" var="a" id="table"> 
<apex:facet name="footer">
<apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error"/>
</apex:facet>
<apex:column headerValue="Class Name">
<apex:inputField value="{!a.Class_Name__c}"/>
</apex:column>
<apex:column headerValue="Board/University">
<apex:inputField value="{!a.Session__c}"/>
</apex:column>
<apex:column headerValue="Percentage">
<apex:inputField value="{!a.Percentage__c}"/>
</apex:column>
<apex:column headerValue="Passing Year">
<apex:inputField value="{!a.Passing_Year__c}"/>
</apex:column>
</apex:pageBlockTable>
<center><br/><br/>
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</center>
</apex:pageBlock>
</span>
</apex:form>
</apex:page>