Radio Group on a Visualforce Page | Techila
single,single-post,postid-1039,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive

Radio Group on a Visualforce Page


Radio Group on a Visualforce Page

“We want a radio group on a Visualforce page. The values for the radioGroup items on should come from the available picklist items of a custom field and depending upon certain parameters, some of the radio group items should be disabled.” Sounds simple! But this could never be accomplished using standard Visualforce.

<apex:dynamicComponent componentValue=”{!dynamicRadioGroup}”/>

Here’s the Apex to create a dynamic radio group:

public Component.Apex.form getDynamicRadioGroup() {

 //I put the form component in here. You may not want to do this

   Component.Apex.form form = new Component.Apex.form();


   Component.Apex.outputLabel label = new Component.Apex.outputLabel();

      label.value = ‘My Dynamic Radio Group’;

  Component.Apex.selectRadio radioGroup = new Component.Apex.selectRadio(); = ‘selectRadio’;


   for (integer i=0;i<5;i++) 


      Component.Apex.selectOption so = new Component.Apex.selectOption();

         so.itemValue = string.valueOf(i+1);

         so.itemLabel = ‘Item # ‘ + string.valueOf(i+1);

         so.itemDisabled = math.mod(i,2)==0;



   Component.Apex.selectOption so = new Component.Apex.selectOption();

      so.itemValue = ‘Random’;

      so.itemLabel = ‘Random’;

      so.itemDisabled = false;




   return form;



You can see in the example above how I created an entire form and added other components (i.e. outputLabel) to the page just using Apex. For the sample code, I’m disabling the even numbered items.  Here’s what it looks like:

Dynamic Visualforce RadioGroup





Author: techila

No Comments

Post A Comment