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
Victor19Victor19 

Rendered attribute for multiple page block sections

Hi,

 

I have 4 checkboxes and 4 pageblock sections in my visualforce page.

 

Conditions:

When I check checkbox 1 -> Section 1&3 has to get displayed

When I check checbox 2 -> Section 1&3 has to get displayed 

Checkbox 3 -> Section 2

Checkbox 4 -> Section 4

 

Currently it works For Checkbox 1. But when I use the same rendered attribute value for Checkbox 2 both the checkboxes (1 & 2) stop working. I don't want to duplicate the sections. I would like to use the same attribute so that it returns the same section.

 

I would really appreciate if someone could give me any suggestions or feedback.

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
liron169liron169
It's possible that you have issue since the isChecked are String, and not boolean.

In addition, I see only one outputPanel in your code, where do you rendered the other 3 sections?

All Answers

liron169liron169

Not sure I understand the problem, but sound like it should be something like:

 

 

<!--Section 1 -->
<apex:outputPanel rendered="{!checkBox1 || checkBox2}">
    <!--contenct -->
</apex:outputPanel>

 


<!--Section 2 -->
<apex:outputPanel rendered="{!checkBox3}">
    <!--contenct -->
</apex:outputPanel>

 

 

If still have problem post also the code, maybe you have syntax error.

Victor19Victor19

Liron169,

 

That is exactly what I am looking for. I tried out the output panel, but the checkboxes stopped working. The code I have works fine for 1 checkbox ->1 section but it doesn't seem to work for 3 checkboxes -> 1 section. 

 

Could you please point out where I have gone wrong or suggest any updates to the code. Below is my visualforce and apex code:

 

//Visualforce Code:

<apex:page standardcontroller="Test__c" extensions="reference" tabStyle="Test__c">
<apex:form >

<apex:pageBlock >

<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>


<apex:pageBlockSection title="SECTION A:" columns="1" >
<apex:pageBlockSectionItem >
<apex:inputCheckbox id="isChk1" value="{!isChecked1}">
<apex:outputLabel for="isChk1" value="Checkbox1"/>
<apex:actionsupport event="onclick" rerender="SampleView1" />
</apex:inputCheckbox>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:inputCheckbox id="isChk2" value="{!isChecked2}" >
<apex:actionsupport event="onclick" rerender="SampleView1" />
<apex:outputLabel for="isChk2" value="Checkbox2"/>
</apex:inputCheckbox>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:inputCheckbox id="isChk3" value="{!isChecked3}" >
<apex:actionsupport event="onclick" rerender="SampleView1" />
<apex:outputLabel for="isChk3" value="Checkbox3"/>
</apex:inputCheckbox>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:inputCheckbox id="isChk4" value="{!isChecked4}" >
<apex:actionsupport event="onclick" rerender="SampleView1" />
<apex:outputLabel for="isChk4" value="Checkbox4"/>
</apex:inputCheckbox>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>


<apex:outputPanel id="SampleView1">

<apex:pageBlockSection title="SECTION B:" rendered="{!isChecked3}" columns="1" >
<apex:inputCheckbox value="{!Test__c.Field1__c}" label="{!ref.Field1__c}"/>
<apex:inputCheckbox value="{!Test__c.Field2__c}" label="{!ref.Field2__c}"/>
</apex:pageBlockSection>


<apex:pageBlockSection title="SECTION C:" rendered="{!isChecked1|| isChecked2 || isChecked4 }" columns="1" > 
<apex:inputCheckbox value="{!Test__c.Field3__c}" label="{!ref.Field3__c}"/>
</apex:pageBlockSection>
</apex:outputPanel>

<apex:pageBlockSection title="SECTION D:" columns="1" > 
<apex:inputCheckbox value="{!Test__c.Field4__c}" label="{!ref.Field4__c}"/>
</apex:pageBlockSection>

<apex:pageBlockSection title="SECTION E:" columns="1" >
<apex:inputCheckbox value="{!Test__c.Field4__c}" label="{!ref.Field4__c}"/>
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:page>

 

 

//Apex Code:

public class reference {
public Reference__c ref;
public String isChecked1 { get; set; }
public String isChecked2 { get; set; }
public String isChecked3 { get; set; }
public String isChecked4 { get; set; }

public reference(ApexPages.StandardController controller) {

}

public Reference__c getref(){
ref = [select Field1__c, Field2__c, Field3__c, Field4__c from Reference__c WHERE Name = 'R-0003' LIMIT 1];
return ref;

}
}

 

Thanks!

 

Victor19Victor19
Hi liron,

Do you have any suggestions or feedback?
liron169liron169
It's possible that you have issue since the isChecked are String, and not boolean.

In addition, I see only one outputPanel in your code, where do you rendered the other 3 sections?
This was selected as the best answer
Victor19Victor19
Thanks! that was the issue.. I changed the String to Boolean and it worked.

I really appreciate your help