+ Start a Discussion
KbhaskarKbhaskar 

dynamically render a pageblock based on radiobutton onchange

hi, 
the below code(Still incorrect) is dynamically render a label value based on radiobutton onchange.but how i can  dynamically render a pageblock based  radiabutton onchange ?
 
<apex:page controller="Sample34">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                Object Permissions:
                <apex:selectRadio >
                    <apex:selectOption id="read1" itemLabel="Read" itemValue="f"  />
                    <apex:selectOption id="write1" itemLabel="Write" itemvalue="cpp" />   
                    <apex:actionsupport event="onchange"  rendered="sampleView" />
               </apex:selectRadio>
            </apex:pageBlockSection>
            <apex:outputPanel id="SampleView">
                <apex:pageBlockSection rendered="{!isChecked}">
                    <apex:pageblockSectionItem >
                        <apex:outputlabel value="Section 1"/>
                    </apex:pageblockSectionItem>                           
                </apex:pageBlockSection>
                <apex:pageBlockSection rendered="{!IF(isChecked = true , false , true)}">
                    <apex:pageblockSectionItem >
                        <apex:outputlabel value="Section 2"/>    
                    </apex:pageblockSectionItem>            
                </apex:pageBlockSection>
            </apex:outputPanel>
            <apex:pageBlockButtons >
                <apex:commandButton value="Assign"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Class
public class Sample34 {

    public Boolean isChecked { get; set; }
}

 
Best Answer chosen by Kbhaskar
Alexander TsitsuraAlexander Tsitsura
Hi bhaskar,

Try code below

Vf page
<apex:page controller="Sample34">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                Object Permissions:
                <apex:selectRadio value="{!selectedValue}">
                    <apex:selectOption id="read1" itemLabel="Read" itemValue="f"  />
                    <apex:selectOption id="write1" itemLabel="Write" itemvalue="cpp" />   
                    <apex:actionSupport event="onchange" reRender="SampleView" />
               </apex:selectRadio>
            </apex:pageBlockSection>
            
            <apex:outputPanel id="SampleView">
                <apex:pageBlockSection rendered="{!IF(selectedValue == 'f', true, false)}">
                    <apex:pageblockSectionItem >
                        <apex:outputlabel value="f"/>
                    </apex:pageblockSectionItem>                           
                </apex:pageBlockSection>
                <apex:pageBlockSection rendered="{!IF(selectedValue == 'cpp', true, false)}">
                    <apex:pageblockSectionItem >
                        <apex:outputlabel value="cpp"/>    
                    </apex:pageblockSectionItem>            
                </apex:pageBlockSection>
            </apex:outputPanel>
            <apex:pageBlockButtons >
                <apex:commandButton value="Assign"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Apex Controller
public with sharing class Sample34 {



    public Boolean isChecked { get; set; }
    public String selectedValue {get;set;}
}

Let me know if it's help.

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex

All Answers

Alexander TsitsuraAlexander Tsitsura
Hi bhaskar,

Try code below

Vf page
<apex:page controller="Sample34">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                Object Permissions:
                <apex:selectRadio value="{!selectedValue}">
                    <apex:selectOption id="read1" itemLabel="Read" itemValue="f"  />
                    <apex:selectOption id="write1" itemLabel="Write" itemvalue="cpp" />   
                    <apex:actionSupport event="onchange" reRender="SampleView" />
               </apex:selectRadio>
            </apex:pageBlockSection>
            
            <apex:outputPanel id="SampleView">
                <apex:pageBlockSection rendered="{!IF(selectedValue == 'f', true, false)}">
                    <apex:pageblockSectionItem >
                        <apex:outputlabel value="f"/>
                    </apex:pageblockSectionItem>                           
                </apex:pageBlockSection>
                <apex:pageBlockSection rendered="{!IF(selectedValue == 'cpp', true, false)}">
                    <apex:pageblockSectionItem >
                        <apex:outputlabel value="cpp"/>    
                    </apex:pageblockSectionItem>            
                </apex:pageBlockSection>
            </apex:outputPanel>
            <apex:pageBlockButtons >
                <apex:commandButton value="Assign"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Apex Controller
public with sharing class Sample34 {



    public Boolean isChecked { get; set; }
    public String selectedValue {get;set;}
}

Let me know if it's help.

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex
This was selected as the best answer
KbhaskarKbhaskar
спасибі Алексу !