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
Akash Choudhary 17Akash Choudhary 17 

I want to create VF page

Step 1: which displays a list of contacts with radio button
Step 2: so that when I select one, the related fields to that contact opens and are editable
Step 3:  the last step is to click save after editing.
and it all has to be covered up with a progress indicator
please help.
Best Answer chosen by Akash Choudhary 17
Ajay K DubediAjay K Dubedi
Hi Akash

Try this code

<apex:page controller="RadioButton" showheader="false">
    <apex:form>
        <apex:pageblock id="allcons" title="Available Contacts">
            <apex:pageblocktable id="allcons" value="{!AllContacts}" var="allcon">
                <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:outputfield value="{!allcon.LastName}">
                    </apex:outputfield></apex:column> 
                <apex:column headervalue="First Name">
                    <apex:outputfield value="{!allcon.FirstName}">
                    </apex:outputfield></apex:column>  
                <apex:column headervalue="Email">
                    <apex:outputfield value="{!allcon.Email}">
                    </apex:outputfield></apex:column>  
                <apex:column headervalue="Phone">
                    <apex:outputfield value="{!allcon.Phone}">
                    </apex:outputfield></apex:column>  
            </apex:pageblocktable>
        </apex:pageblock> 
        <apex:pageblock id="consel" title="Selected Contact">
            <apex:pageblocktable id="allcons" value="{!selectedContact}" var="selcon">                       
                <apex:column headervalue="Last Name">
                    <apex:inputField value="{!selcon.LastName}">
                    </apex:inputField>
                </apex:column> 
                <apex:column headervalue="First Name">
                    <apex:inputField value="{!selcon.FirstName}">
                    </apex:inputField>
                </apex:column>  
                <apex:column headervalue="Email">
                    <apex:inputField value="{!selcon.Email}">
                    </apex:inputField>
                </apex:column>  
                <apex:column headervalue="Phone">
                    <apex:inputField value="{!selcon.Phone}">
                    </apex:inputField>
                </apex:column>  
            </apex:pageblocktable>
          <apex:commandButton value="Save" action="{!saveContact}" />
        </apex:pageblock>               
    </apex:form>
</apex:page>

// Apex Controller

public class RadioButton {
    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;
    }
    public void saveContact()
    {
        upsert selectcon;
    }
}


Thanks
Ajay Dubedi

All Answers

Ajay K DubediAjay K Dubedi
Hi Akash

Try this code

<apex:page controller="RadioButton" showheader="false">
    <apex:form>
        <apex:pageblock id="allcons" title="Available Contacts">
            <apex:pageblocktable id="allcons" value="{!AllContacts}" var="allcon">
                <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:outputfield value="{!allcon.LastName}">
                    </apex:outputfield></apex:column> 
                <apex:column headervalue="First Name">
                    <apex:outputfield value="{!allcon.FirstName}">
                    </apex:outputfield></apex:column>  
                <apex:column headervalue="Email">
                    <apex:outputfield value="{!allcon.Email}">
                    </apex:outputfield></apex:column>  
                <apex:column headervalue="Phone">
                    <apex:outputfield value="{!allcon.Phone}">
                    </apex:outputfield></apex:column>  
            </apex:pageblocktable>
        </apex:pageblock> 
        <apex:pageblock id="consel" title="Selected Contact">
            <apex:pageblocktable id="allcons" value="{!selectedContact}" var="selcon">                       
                <apex:column headervalue="Last Name">
                    <apex:inputField value="{!selcon.LastName}">
                    </apex:inputField>
                </apex:column> 
                <apex:column headervalue="First Name">
                    <apex:inputField value="{!selcon.FirstName}">
                    </apex:inputField>
                </apex:column>  
                <apex:column headervalue="Email">
                    <apex:inputField value="{!selcon.Email}">
                    </apex:inputField>
                </apex:column>  
                <apex:column headervalue="Phone">
                    <apex:inputField value="{!selcon.Phone}">
                    </apex:inputField>
                </apex:column>  
            </apex:pageblocktable>
          <apex:commandButton value="Save" action="{!saveContact}" />
        </apex:pageblock>               
    </apex:form>
</apex:page>

// Apex Controller

public class RadioButton {
    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;
    }
    public void saveContact()
    {
        upsert selectcon;
    }
}


Thanks
Ajay Dubedi
This was selected as the best answer
Akash Choudhary 17Akash Choudhary 17
Thanks, Ajay it's working.
Ajay K DubediAjay K Dubedi
Hi Akash,

Can you please mark it as the best answer. 
Thank You.