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
DafuelDafuel 

Rerender Pageblocksection through visualforce checkbox via ajax

I am having a Checkbox on my vf page and what i want is when i click on my chekbox then only my certain pageblocksection/outpanel should be visible.

 

i am using following code on vf:

<apex:pageBlockSection title="Select Countries">
<apex:inputCheckbox value="{!reUSA}" label="USA"><apex:actionSupport event="onchange" reRender="USASection" id="Us"/></apex:inputCheckbox>
  </apex:pageBlockSection>

<apex:outputPanel id="USASection" rendered="{!reUSA}"> <apex:inputField value="{!abc__c.myfield__c}" /></apex:outputPanel>

 

 

 

Apex code:

public Boolean reUSA{get; set;}

 

Now i have used various syntax for rendered attribute like:  rendered="{!IF(reUSA==true,true,false)}"

OR this rendered={!reUSA=true} but the outpanel is not visible when i click on checkbox.

 

Onething i am confirmed about is when i click on checkbox ,its value is set to true...and i have even tried to display that value  and i get true and onchanging the checkbox ,it shows me false and so on true..false.on further clicking..... but  the thing i didn't understand is if its value sets to true/false..then y is it not able to   substitute its "true/false" value in rendered attribute... in place of {!reUSA}. 

Any suggestion wud be appreciated.. :)

Best Answer chosen by Admin (Salesforce Developers) 
amilawamilaw

put another output panel outside the one you are going to show accroding to checkbox value and rerender that.

 

<apex:pageBlockSection title="Select Countries">
<apex:inputCheckbox value="{!reUSA}" label="USA"><apex:actionSupport event="onchange" reRender="USASectionOuter" id="Us"/></apex:inputCheckbox>
</apex:pageBlockSection>

<apex:outputPanel id="USASectionOuter">
<apex:outputPanel id="USASection" rendered="{!reUSA}"> <apex:inputField value="{!abc__c.myfield__c}" /></apex:outputPanel>
</apex:outputPanel>

All Answers

amilawamilaw

put another output panel outside the one you are going to show accroding to checkbox value and rerender that.

 

<apex:pageBlockSection title="Select Countries">
<apex:inputCheckbox value="{!reUSA}" label="USA"><apex:actionSupport event="onchange" reRender="USASectionOuter" id="Us"/></apex:inputCheckbox>
</apex:pageBlockSection>

<apex:outputPanel id="USASectionOuter">
<apex:outputPanel id="USASection" rendered="{!reUSA}"> <apex:inputField value="{!abc__c.myfield__c}" /></apex:outputPanel>
</apex:outputPanel>

This was selected as the best answer
DafuelDafuel
Hey thanks Buddy....btw...wud u plz xlpain me ...the need of another outputpanel...thanks again :)
amilawamilaw

its because there is no html section with id "USASection" in the initial page render (as reUSA is false). so ajax cant identify which area to rerender