how to make selected radio button as checked?

depending upon the selection of radio button it displays the selected row in differnt fields.enter image description here

the selected radio button disappears after the selected row splited.but i want the radio button selected.

vf:

<apex:page standardController="Contact" extensions="RadioButton" showheader="false">
  <apex:form >
    <apex:pageblock id="allcons" title="Available Contacts" mode="inlineedit" >
      <apex:datatable id="allcons" value="{!AllContacts}" var="allcon" cellpadding="2" border="2" >
        <apex:column headervalue="Set as Primary">
          <apex:actionsupport action="{!selectcon}" event="onclick" rerender="consel,allcons">
            <input type="radio" />
            <apex:param name="conid" value="{!allcon.Id}">
          </apex:param>
        </apex:actionsupport>
      </apex:column>
        <apex:column headervalue="Last Name">
          <apex:inputText value="{!allcon.LastName}"/>
        </apex:column>
        <apex:column headervalue="First Name">
          <apex:inputText value="{!allcon.FirstName}"/>
        </apex:column>
        <apex:column headervalue="Email">
          <apex:inputText value="{!allcon.Email}"/>
        </apex:column>
        <apex:column headervalue="Phone">
          <apex:inputText value="{!allcon.Phone}"/>
        </apex:column>
      </apex:datatable>
    </apex:pageblock>
    <apex:pageblock id="consel" title="Selected Contact">
      <apex:pageblocktable id="allcons" value="{!selectedContact}" var="selcon">
        <apex:column headervalue="Last Name">
          <apex:outputfield value="{!selcon.LastName}">
        </apex:outputfield>
      </apex:column>
        <apex:column headervalue="First Name">
          <apex:outputfield value="{!selcon.FirstName}">
        </apex:outputfield>
      </apex:column>
        <apex:column headervalue="Email">
          <apex:outputfield value="{!selcon.Email}">
        </apex:outputfield>
      </apex:column>
        <apex:column headervalue="Phone">
          <apex:outputfield value="{!selcon.Phone}">
        </apex:outputfield>
      </apex:column>
    </apex:pageblocktable>
  </apex:pageblock>
</apex:form>
</apex:page>

controller:

public class RadioButton {

    public RadioButton(ApexPages.StandardController controller) {

    }

    List < contact > selectcon;
    Public List < contact > getAllContacts() {
        List < contact > allcons = [Select Id, FirstName, LastName, Email, Phone from Contact limit 5];
        return allcons;
    }
    Public void selectcon() {
        String selcontactid = System.currentPagereference().getParameters().get('conid');
        Contact con = [Select Id, FirstName, LastName, Email, Phone from Contact where Id = : selcontactid];
        selectcon = new List < contact > ();
        selectcon.add(con);
    }
    Public List < contact > getselectedContact() {
        return selectcon;
    }
}

Answer

your <input type="radio"> tag is not bound to anything. If you would like it to maintain state, you should replace it with an <apex:input> with a value bound to a Ctrl property.

Attribution
Source : Link , Question Author : Mahi , Answer Author : RenegadeCoder

Leave a Comment