+ Start a Discussion
ranveer singh 8ranveer singh 8 

Rendered and rerender

Hi guys,

below is the code in which if we change the value of picklist the details of the selected record has to be shown below and initiallling the detail block should be hidden and on every change of picklist value the detail block should be refreshed

<apex:page controller="sc">
<apex:form >
  Select country:  <apex:selectList size="1" value="{!accid}" >
                      <apex:selectOptions value="{!option}" ></apex:selectOptions> 
                      <apex:actionSupport event="onchange"  action="{!find}" rerender="pb"/> 
                 </apex:selectList><br/><br/>
                 <apex:messages />
                 
                 <apex:outputPanel id="pb" rendered="{!booblock}" >
                 <apex:pageblock title="Detail secton"  >
                 
                 <apex:pageBlockSection id="pbs">
                 <apex:pageBlockTable value="{!acc}" var="a" id="pbt">
                 <apex:column value="{!a.name}"/>
                 <apex:column value="{!a.phone}"/>
                 <apex:column value="{!a.billingcity}"/>
                 </apex:pageBlockTable>
                 </apex:pageBlockSection>
                 </apex:pageblock>
                 </apex:outputPanel>
</apex:form>
</apex:page>

*********************************************

public with sharing class sc {

public boolean booblock{set;get;}
public string accid {set;get;}
public list<selectoption> option {set;get;}
public list<account> acclist = [select id,name from account limit 999];
public account acc{set;get;}

    public sc() {

option = new list<selectoption>();
 option.add(new selectoption('None','None'));
 
for(account ac : acclist){
option.add(new selectoption(ac.id,ac.name));

    }
    }

public void find(){


try{
acc = [select id,name,phone,billingcity from account where id =:accid];
booblock = true;
}
catch(exception e){
system.debug('exception type is'+e.gettypename());
system.debug('exception message is'+e.getMessage());
ApexPages.addMessages(e);
/*ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter value'));*/
}
}
}

But in the above code if i remove the "rendered="{!booblock}" " component it is working fine ...but here my requirement is detail component should be shown only when picklist value is changed any help would be appriciated
Best Answer chosen by ranveer singh 8
Magesh Mani YadavMagesh Mani Yadav
Hi Ranveer,

You need to update two lines of VF code. Move your rendered="{!booblock}" from OutputPanel to its Child (pageblock).
Salesforce doesn't rerender the target element if it has rendered attribute.
So the below change should work for you.
<apex:outputPanel id="pb"  >
<apex:pageblock title="Detail secton" rendered="{!booblock}"  >

 

All Answers

Magesh Mani YadavMagesh Mani Yadav
Hi Ranveer,

You need to update two lines of VF code. Move your rendered="{!booblock}" from OutputPanel to its Child (pageblock).
Salesforce doesn't rerender the target element if it has rendered attribute.
So the below change should work for you.
<apex:outputPanel id="pb"  >
<apex:pageblock title="Detail secton" rendered="{!booblock}"  >

 
This was selected as the best answer
ranveer singh 8ranveer singh 8
Thku magesh i will tr