0

VF:

<apex:pageBlock>
<table>
<apex:repeat value="{!accList2}" var="a" >
<tr>
<apex:repeat value="{!a}" var="am">
<td> {!am.id} </td> 
<td> <input type="radio" name="radio1" id=""  value="{!am.name}"  onclick="test()" /> {!am.name}  
</td>
<td> <input type="radio" name="radio2" id=""  value="{!am.phone}" onclick="test()" /> 
{!am.phone} </td>
</apex:repeat>   </tr>
</apex:repeat>
</table>
</apex:pageBlock>

Apex:

Public List<String> selectedFieldValues {get;set;}
accList2 =[select id,name,phone,billingcity from acount where id IN: idList];

enter image description here

Basically I'm trying to get the selected radio button values to apex controller and store in List and then update account fields using visual force page similar to standard functionality.

Can someone please suggest me how to achieve this functionality using vf and apex.

Thank you,

1 Answer 1

0

When it comes to Visualforce and checkboxes or radio buttons, a wrapper class is likely required (even more likely if you're using something like a pageblocktable or apex:repeat).

The idea is that your wrapper class contains the SObject record that you want to pull your data from as well as having String and/or Boolean fields to capture the data from the inputs on your page that can't be mapped to a field on your SObject (or at least can't be easily mapped).

A simple example

public class MyControllerExtension{
    // Instead of using the SObject record directly, we'll go through a wrapper
    List<MyWrapper> wrappedList {get; set;}

    public MyControllerExtension(ApexPages.StandardController con){
        // constructor work
        wrappedList = new List<MyWrapper>();
    }

    public void getRecords(){
        // Somewhere, you need to get a list of records and use them to create
        //   instances of your wrapper
        for(MyObject__c record :[some query]){
            MyWrapper wrapper = new MyWrapper();
            wrapper.record = record;
        }
    }

    // The wrapper doesn't need to be fancy
    // A simple inner class like this works fine
    public class MyWrapper{
        MyObject__c record {get; set;}
        String radioValue {get; set;}
    }
}
<apex:page>
    <apex:form>
        <apex:repeat value="{!wrappedList}" var="wrapper">
            <apex:inputField value="{!wapper.record.Name}" />
            <apex:input type="radio" name="myRadio" value="{!wrapper.radioValue}" />
        </apex:repeat>
    </apex:form>
</apex:page>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .