+ Start a Discussion
shephalishephali 

Replace CheckBox with Radio Button

Hi All,

     I need to use radio button in place of CheckBoxes. But when i try to change the VF tag It is not working.
// The Below code is working fine with no issue //
 <apex:column >
       <apex:inputCheckbox value="{!con.isSelected}" />
  </apex:column> 

///////This is the code which i am using for Radio button. Its showing the radio button but functionality is not working here in case of Radio ////

   <apex:column >                    
       <input type="radio" value= "{!con.isSelected}" />                                     
    </apex:column>

Kindly help me on this.
Anilkumar KotaAnilkumar Kota

Hi Shephali,
 

<!-- Page: -->
<apex:page controller="sampleCon">
    <apex:form>
        <apex:selectRadio value="{!country}">
            <apex:selectOptions value="{!items}"/>
            </apex:selectRadio><p/>
            <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
     </apex:form>
     <apex:outputPanel id="out">
          <apex:actionstatus id="status" startText="testing..."> 
             <apex:facet name="stop"> 
               <apex:outputPanel> 
                  <p>You have selected:</p> 
                 <apex:outputText value="{!country}"/> 
              </apex:outputPanel> 
            </apex:facet> 
          </apex:actionstatus> 
     </apex:outputPanel> 
</apex:page>
            
/*** Controller ***/
public class sampleCon {
    String country = null;
         
    public PageReference test() {
        return null;
    }
                
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('US','US')); 
        options.add(new SelectOption('CANADA','Canada')); 
        options.add(new SelectOption('MEXICO','Mexico')); return options; 
    }
                   
    public String getCountry() {
        return country;
    }
                    
    public void setCountry(String country) { this.country = country; }
}

 

Hope this will help you..!

shephalishephali
@AnilKumar,

   Hi thanks for reply. I have tried such code. The problem it always shows all the Options in one ROW only i need it one option and second in next line and so on...Thats why i tried the HTML tag <Input type= "radio">. But dint get success as it shows the data i wanted but functionality is not achieved.

Thanks
shephalishephali
@AMit Singh... Thanks for reply.. Hope now you understood my actual requirement.
Thiruchuri AdityanThiruchuri Adityan
I think you can use <br/> tag at the selectoptions tag for a line break..
Akshay SoniAkshay Soni
Use layout="pagedirection" attribute in <apex:selectRadio> tag.