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
David9133David9133 

pageblocktable with rows and columns and radio buttons as input values ?

HI I would like to know How to develop pageblocktable with first column as list of record names from the Master object and other 3 columns as input radio button and it should select only one radio button per record , I have to capture the result and save the column header value in the field with the record Name in another field in the child object.
 
Ispita Saha 20Ispita Saha 20
Can you attach a screenshot for clarity or just Type the output you want!
VineetKumarVineetKumar
Your page would look something like this
PAGE:
<apex:pageBlockTable value="{!SurveyQuestions}" var="sq">
        <apex:column value="{!sq.questions}"/>
        <apex:column headerValue="Question options 1">
            <apex:selectRadio value="{!sq.answer1}">
              <apex:selectOptions value="{!items}"/>
            </apex:selectRadio> 
        </apex:column>  
		<apex:column headerValue="Question options 2">
            <apex:selectRadio value="{!sq.answer2}">
              <apex:selectOptions value="{!items}"/>
            </apex:selectRadio> 
        </apex:column>  
		<apex:column headerValue="Question options 3">
            <apex:selectRadio value="{!sq.answer3}">
              <apex:selectOptions value="{!items}"/>
            </apex:selectRadio> 
        </apex:column>  		
    </apex:pageBlockTable>

CONTROLLER:	
	public List<SelectOption> getItems() {
		List<SelectOption> options = new List<SelectOption>(); 
		options.add(new SelectOption('1','1')); 
		options.add(new SelectOption('2','2')); 
		options.add(new SelectOption('3','3')); 
		return options; 
	}

	public List<SurveyQuestionsWrapper> SurveyQuestions = new List<SurveyQuestionsWrapper>();
	public class SurveyQuestionsWrapper{
		public String question {get; set;}
		public Boolean answer1 {get; set;}
		public Boolean answer2 {get; set;}
		public Boolean answer3 {get; set;}
		
		public SurveyQuestionsWrapper(String question, Boolean answer1, Boolean answer2, Boolean answer3){
			this.question = question;
			this.answer1 = answer1;
			this.answer2 = answer2;
			this.answer3 = answer3;			
		}
	}
Above is psuedo code.. you need to develop your functionality around it
 
David9133David9133
Hi VineetKumar,

Thanks for the reply i modified the code according to the exampl you mentioned. But when the page is loading value is getting selected for all the records loaded in the pageblock table . I am not able to get the selected value records in the controller with the value, Please help me to capture the list of selected records and get the value of the Proficiency.

Page:
<apex:page sidebar="false" controller="RadioinputController">
<apex:form >
<apex:pageBlock id="block3">
<apex:pageBlockTable value="{!skills}" var="sq">
<apex:column value="{!sq.Skill.Name}"/>
<apex:column headerValue="Proficiency">
<apex:selectRadio value="{!sq.answer1}">
<apex:selectOptions value="{!items}"/> </apex:selectRadio> </apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons location="Bottom">
<apex:commandButton action="{!save}" value="save"/>
</apex:pageBlockButtons>
</apex:pageBlock> </apex:form> </apex:page>

controller:
Public Class RadioinputController
{
 public List<SkillsWrapper> skills {get;set;}
 public List<Skill__c> selectedskillrecord {get;set;}
    
    public RadioinputController()
    {
      skills  = new List<SkillsWrapper>();
      for(Skill__c s : [select Name From Skill__c ] )
          {
              skills.add(new SkillsWrapper(s));
          }
    }

    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Basic Knowledge','Basic Knowledge'));
        options.add(new SelectOption('Intermediate','Intermediate'));
        options.add(new SelectOption('Advanced','Advanced'));
        return options;
    }
    public class SkillsWrapper{
        public Skill__c skill {get; set;}
        public Boolean answer1 {get; set;}
        public SkillsWrapper(Skill__c s){
            Skill = s;
            answer1 = false;
        }
    }
 
    public void selectedrecords() {
        selectedskillrecord = new List<Skill__c>();
        for(SkillsWrapper wrapobj: skills){
           if(wrapobj.answer1==true){
           selectedskillrecord.add(wrapobj.skill);
           }        
         }
             }   
    public pagereference save()
        {
        system.debug('Selected Records:' +selectedskillrecord); 
        return Null;
        }
}

Screenshot:
Screenshot Output
VineetKumarVineetKumar
For <apex:selectRadio> one value is selected by default, as atleast one must be selected.
For getting the value in controller, you need to do something like this:
public pagereference save(){
    for(SkillsWrapper swObject :  skills){
        selectedskillrecord.add(swObject.answer1);
    }
    system.debug('Selected Records:' +selectedskillrecord); 
    return Null;
}