3

I have built a dyanmic component as selectOption (select radio with select option values). I need to know how can I access the selected value? (which radio button is selected?)

Below is my code

VF

<apex:dynamicComponent componentValue="{!CustomInsuranceProducts}"/>

Apex class

public Component.Apex.selectRadio getCustomInsuranceProducts(){                  
        Component.Apex.selectRadio myCustomRadio = new Component.Apex.selectRadio();

        myCustomRadio.id = 'Insurance_Package';                     
        for(ApplicantProductWrapper myappprod : mapApplicantProduct.get(Constants.INSURANCE)) {
            Component.Apex.selectOption so = new Component.Apex.selectOption();
            so.itemValue = myappprod.applicantProduct.Product__c;                
            Component.Apex.OutputText output = new Component.Apex.OutputText();
            output.expressions.value = '{!$Label.' + myappprod.Prod.description__c + '}';
            string labelValue = string.valueOf(output.value);                    
            so.itemLabel = labelValue;
            myCustomRadio.childComponents.add(so);
    }       
       return myCustomRadio;
}
2

You need to define a value parameter of the selectRadio component and assign some string variable to it:

public String selectedValue { get; set; }

public Component.Apex.selectRadio getCustomInsuranceProducts(){                  
    Component.Apex.selectRadio myCustomRadio = new Component.Apex.selectRadio();
    myCustomRadio.id = 'Insurance_Package';

    selectedValue = [SELECT Id from .....];

    myCustomRadio.expressions.value = '{!selectedValue}';
  • what does selectedValue hold? Which value should I assign to it? I do not know what is the selected value – sfdcFanBoy Sep 4 '14 at 3:50
  • @BruceLee It is a variable that is associated with this selectRadio component. It holds selected radio button value. Read more about value parameter of the apex:selectRadio component. – Sergej Utko Sep 4 '14 at 6:48
  • Yup, it indeed worked. I had to assign the appropriate value from the record to this variable in the for loop. selectedValue = map.get(package); – sfdcFanBoy Sep 8 '14 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.