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
Suresh Kumar Arjunan1Suresh Kumar Arjunan1 

selected values not passing to controller - dynamic visual force

Friends,

I'm trying to pass the selected checkboxes and radio button values from vf to controller and it is not working. Can someone throw lights on this please?

Refer method --> component.apex.SelectCheckboxes sc

My controller class:
----------------------------

public class dynamicQuestions {
public string str {get; set;}
public List<String> s { get; set; }
public static List<String> selected = new List<String>();
public Map<Id,Export_Compliance__c> m = new Map<Id,Export_Compliance__c>();
public Map<String, rWrapper> rWrap {get; set;}
Map<Id, List<Question_Response__c>> final1 = new Map<Id, List<Question_Response__c>>();
Map<Id, Question_Response__c> rType = new Map<Id, Question_Response__c>();
List<Question_Response__c> Ques = new List<Question_Response__c>();
Map<Id, rWrapper> fWrapper {get; set;}
Map<Id, List<String>> strList {get; set;}
public Map<Id, List<String>> z { get; set; }

public class rWrapper {
public string sflag {get; set;}
public List<String> lstr {get; set;}
public List<Question_Response__c> QRlist {get; set;}
}

public dynamicQuestions(){
z = new Map<Id, List<String>> ();
List<Export_Compliance__c> os = new List<Export_Compliance__c>([select Id, name, Parent__c,Response_Type__c,Opportunity__c, Question_Id__c from Export_Compliance__c]);
Ques = [select Id, name, Response_Type__c, Question__c, Parent_Question_Id__c, Response__c from Question_Response__c];
s = new List<string>();
fWrapper = new Map<Id, rWrapper>();
rWrap = new Map<String, rWrapper>();
strList = new Map<Id, List<String>>();
system.debug('frwapper within constructor :' + fWrapper);
for(Export_Compliance__c e : os)
{

    if(e.Response_Type__c=='Radio')
    {
        rWrapper w = new rWrapper();
        w.sflag=e.Question_Id__c;
        rWrap.put(e.Parent__c, w);
        system.debug('------rWrap---------'+rWrap + ' Parent Q is -->: '+e.Parent__c);
    }
    if(e.Response_Type__c=='Multi')
    {    
        List<string> tempList = new List<string>();
        if(strList.get(e.Parent__c) !=null)
        {
            tempList = strList.get(e.Parent__c);
        } 
        tempList.add(e.Question_Id__c);
        strList.put(e.Parent__c,tempList);
        s.add(e.Question_Id__c);
    }
    
m.put(e.Question_Id__c,e);
}


   for(Question_Response__c qq : Ques)
    {
    
       // rWrapper w = new rWrapper();
        


    //Stores Master Question's response
        if(qq.Parent_Question_Id__c == null)
        {
            rType.put(qq.Id, qq);
        }
    
    //Forms a map with master question and its list of responses.
        if(qq.Parent_Question_Id__c!= null)
        {
            if(final1.get(qq.Parent_Question_Id__c)==null)
            {
                List<Question_Response__c> a = new List<Question_Response__c>();
                a.add(qq);
                final1.put(qq.Parent_Question_Id__c, a);
            } else {
                List<Question_Response__c> b = new List<Question_Response__c>();
                b = final1.get(qq.Parent_Question_Id__c);
                b.add(qq);
                final1.put(qq.Parent_Question_Id__c, b);
            }
        }
        
        if(qq.Parent_Question_Id__c!= null)
        {
            rWrapper w = new rWrapper();
            List<Question_Response__c> a = new List<Question_Response__c>();
            //If statement to set list of responses
            if(fWrapper.get(qq.Parent_Question_Id__c)==null)
            {
                a.add(qq);
                w.QRlist = a;                
            } else {
                w = fWrapper.get(qq.Parent_Question_Id__c);
                a=w.QRlist;
                a.add(qq);
            }
            //If statement to set list of checkboxes selection
           if(strList.get(qq.Parent_Question_Id__c) == null){
               w.lstr = new List<string>();             
            } else {
               w.lstr = strList.get(qq.Parent_Question_Id__c);
            }
            //If statement to string of radio selection            
           if(rWrap.get(qq.Parent_Question_Id__c)!=null){
            w.sflag = rWrap.get(qq.Parent_Question_Id__c).sflag;
            }
            
            fWrapper.put(qq.Parent_Question_Id__c, w);
            
system.debug('your fWrapper------------'+fWrapper);    
        }
    }
}

public Component.Apex.OutputPanel getRadio(){

component.apex.OutputPanel op = new component.apex.OutputPanel();
op.id = 'outPanel';

for(Id myQR : fWrapper.keyset()){

if(rType.get(myQR).Response_Type__c == 'Radio'){
component.apex.outputlabel myRlabel = new component.apex.outputlabel();
component.apex.outputText ot = new component.apex.outputText();
ot.value = rType.get(myQR).Question__c;
myRlabel.childcomponents.add(ot);
system.debug('============='+ rWrap.get(myQR).sflag+' @@@@@@@@@@ '+myQR);
myRlabel.childcomponents.add(sr(fWrapper.get(myQR).QRlist,myQR,fWrapper.get(myQR).sflag));
op.childcomponents.add(myRlabel);
}

if(rType.get(myQR).Response_Type__c == 'Multi'){
component.apex.outputlabel myRlabel = new component.apex.outputlabel();
component.apex.outputText ot = new component.apex.outputText();
ot.value = rType.get(myQR).Question__c;
myRlabel.childcomponents.add(ot);
myRlabel.childcomponents.add(sc(fWrapper.get(myQR).QRlist, myQR, fWrapper.get(myQR).lstr));
op.childcomponents.add(myRlabel);
}


}

return op;
}
//pass wrapper as input to this method and use that in expressions????give a try
public component.apex.selectRadio sr(List<Question_Response__c> myR, String pId, String aaa){


component.apex.selectRadio ssr = new component.apex.selectradio(Id=pId, layout='pageDirection');


for(Question_Response__c childq : myR)
{
        if(m.ContainsKey(childq.Id))
        {
            ssr.value=aaa;
            system.debug('-------: '+aaa);
        }
    component.apex.selectoption so = new component.apex.selectoption();
    so.itemvalue = childq.Id;
    so.itemlabel = childq.Response__c;
    ssr.childcomponents.add(so);
}
return ssr;
}

public component.apex.SelectCheckboxes sc(List<Question_Response__c> myR, String pId, List<string> xyz){
system.debug(';;;;;;;;;;;;;'+xyz);
component.apex.SelectCheckboxes ssc = new component.apex.SelectCheckboxes(Id=pId, Layout='pageDirection');
//z.put(pId, xyz);
//ssc.value=xyz;
ssc.value = fWrapper.get(pId).lstr;
//List<SelectOption> options = new List<SelectOption>();
for(Question_Response__c childq : myR)
{
    //options.add(new SelectOption(childq.Response__c,childq.Id));

    component.apex.selectoption so = new component.apex.selectoption();
    system.debug('child Id reference :'+childq.Id);
    so.itemvalue = childq.Id;
    so.itemlabel = childq.Response__c;
    ssc.childcomponents.add(so);
}
return ssc;
}


public pageReference createRecords(){

system.debug('selected Records fWrapper ---> '+fWrapper);

return null;

}


}

My VF Page
-----------------

<apex:page controller="dynamicQuestions">
<apex:form id="myform">
<apex:commandButton action="{!createRecords}" value="Save" reRender="myform"/><br/>
<apex:dynamicComponent componentValue="{!Radio}" id="magic"/>
</apex:form>
</apex:page>