Radio Group on a Visualforce Page | Techila
1039
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-fupdated

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();

      radioGroup.id = ‘selectRadio’;

      radioGroup.layout=’pageDirection’;

   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;

      radioGroup.childComponents.add(so); 

   }

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

      so.itemValue = ‘Random’;

      so.itemLabel = ‘Random’;

      so.itemDisabled = false;

   form.childComponents.add(Label);

   form.childComponents.add(radioGroup);

 radioGroup.childComponents.add(so);

   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

DYNAMIC VISUALFORCE RADIOGROUP

 

 

 Courtesyhttp://www.redpointcrm.com/build-killer-visualforce-pages-with-dynamic-visualforce-components

Author: techila

No Comments

Post A Comment