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
Avishek Roy 18Avishek Roy 18 

Not able to pass 'Radio' button selected value in 2nd VF page

Appreciate if someone can help, as i am struggling to resolve the issue for last 3 days.
Requirement: In our application there is a custom Object created name 'Vehicle'. There is another junction object named Vehicle Relationship. 'Vehicle Relationship' has lookup relationship with Accunt and Vehicle. Requirement is to open a VF page(VF Page1) by calling a button in the Vehicle screen. And it will display all the relationship it has with customers. In this view customer would like to have 'Radio' button against those relationship records, so that only 1 record can be selected. Once you can click on a button in this VF page 1, it should navigates to another VF page2 and display the relationship records for user confirmation.Both the VF page is using same custom controller. And both VF page is not Using any standard controller. 

Problem i am facing: I configured the functionality using wrapper class. When i am using 'Checkbox' in the first VF page, it is able to correclty navigates to the second page and showing the records in VF page 2. But when i am using the 'Radio' button on VF page 1, after clicking button VF page 2 is not showing any records. When i am selecting the records with Radio button i am passing the paramer to controller. Seems issue in Radio button selection records.

Can you please help me why for Radio buttion i am not able to retrive records in VF page2. I am not giving the code for 'Checkbox' here as it is working fine. Sharing below the codes for 'Radio' button selection.
VFPage1
<apex:page controller="cVehiclesendwrapperRadioButton">
<apex:form >
    <script>
         function myFunction()
         { 
         var i = {!RecordSize};
         var SelectedRecordIdInbox;
         
         for(j=0;j<i;j++)
         {
         
             if(document.getElementsByName("SelectedCustomer")[j].checked)
             {
                SelectedRecordIdInbox = document.getElementsByName("SelectedCustomer")[j].value;
                
             }
         
         }
          PassTheVariableToController(SelectedRecordIdInbox);
        }
        
    </script>
    <apex:pageBlock >
        <apex:pageBlockTable value="{!LstWrp}" var="w">
       
            <apex:column headerValue="Select">
                 <input value="1" Name="SelectedCustomer" type="radio"/>
            </apex:column>
            <apex:column value="{!w.VehicleRelation.Name}" headerValue="Customer Name"/>
            <apex:column value="{!w.VehicleRelation.OwnerId}" headerValue="Owner"/>
            <apex:column value="{!w.VehicleRelation.Vehicles__c}" headerValue="Vehicles"/>
            <apex:column value="{!w.VehicleRelation.Customer__c}" headerValue="Customer Name"/>
            <apex:column value="{!w.VehicleRelation.customer__r.Id}" headerValue="Customer Id"/>
         </apex:pageBlockTable>
         <apex:pageBlockButtons >
             <apex:commandButton value="Select" onclick="myFunction(); return false;"/>
         </apex:pageBlockButtons>
         
          <apex:actionFunction name="PassTheVariableToController" action="{!RedirectSelectedAcc}" rerender="Pb2">
                <apex:param name="P1" value="" assignTo="{!Param1}"/>
          </apex:actionFunction>
          
    </apex:pageBlock>
</apex:form>


</apex:page>
VFPage2
<apex:page controller="cVehiclesendwrapperRadioButton">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!LstWrpSelected }" var="w1">
            <apex:column value="{!w1.VehicleRelation.Name}" headerValue="Customer Name"/>
            <apex:column value="{!w1.VehicleRelation.OwnerId}" headerValue="Owner"/>
            <apex:column value="{!w1.VehicleRelation.Vehicles__c}" headerValue="Vehicles"/>
            <apex:column value="{!w1.VehicleRelation.Customer__c}" headerValue="Customer Name"/>
            <apex:column value="{!w1.VehicleRelation.customer__r.Id}" headerValue="Customer Id"/>
         </apex:pageBlockTable>
     </apex:pageBlock>
</apex:form>

</apex:page>
Controller Code:
public class cVehiclesendwrapperRadioButton {

    public List<VehicleSelectCheckbox> LstWrp {get; set;}
    public List<VehicleSelectCheckbox> LstWrpSelected {get; set;}
    public string VehId {get; set;}
    public integer RecordSize {get; set;}
    public integer Param1 {get; set;}
    
    public cVehiclesendwrapperRadioButton()
    {
        LstWrp= new List<VehicleSelectCheckbox>();
        LstWrpSelected = new List<VehicleSelectCheckbox>();
        VehId = ApexPages.currentPage().getParameters().get('id');

        List<Vehicle_Relationship__c> VRQuery = new List<Vehicle_Relationship__c>([SELECT Id,Name,OwnerId,Vehicles__c, customer__c, 
                                                                                   customer__r.Id, customer__r.Name, Vehicles__r.Id, Vehicles__r.Name
                                                                                    FROM Vehicle_Relationship__c WHERE Vehicles__c =:VehId]);
        for(integer i=0;i<VRQuery.size();i++)
        {
        
           LstWrp.add(new VehicleSelectCheckbox(VRQuery[i]));
        
        }     
        
        RecordSize= LstWrp.size();                                                                   
    
    }
    
    public Pagereference RedirectSelectedAcc()
    {
        LstWrpSelected = new List<VehicleSelectCheckbox>();
       
        for(VehicleSelectCheckbox wrp:LstWrp)
        {
            if(Param1==1)
            {
                LstWrpSelected.add(wrp);
        
            }
            
          }
        
        PageReference P=Page.VehiclesendwrapperRadioButtonView;
        P.setredirect(true);
        return P;
    }
    
    
    //----Wreapper Class Started----
    
    public class VehicleSelectCheckbox
    {
    
        public boolean RadioButton {get; set;}
        public Vehicle_Relationship__c VehicleRelation {get; set;}
        
        
        public VehicleSelectCheckbox()
        {
        
        }
        
         public VehicleSelectCheckbox(boolean b, Vehicle_Relationship__c VR)
        {
            this.RadioButton=b;
            this.VehicleRelation=VR;
        }
        
        
         public VehicleSelectCheckbox(Vehicle_Relationship__c VR)
        {
            this.RadioButton=false;
            this.VehicleRelation=VR;
        }
    
    }
     //End of wrapper class

}