I have a pageBlockTable that gets its items from a database list from the controller
I'm trying to add in that pageblockTable a column for radiobuttons so the user can select only one row.
I tried this but the radiobuttons are not binded together(I can select more than one item)
apex:pageBlockTable value="{!myContacts}" var="c" id="agents" style="margin-top:1em; width:880px">
<apex:column >
<apex:facet name="header"></apex:facet>
<apex:selectRadio label="selectRadio" id="selectRadio" layout="pageDirection" value="{!c.selected}">
</apex:selectRadio>
</apex:column>
<apex:column >
<apex:facet name="header">Agent Details</apex:facet>
<apex:outputField value="{!c.con.LastName}" />
</apex:column>
</apex:pageBlockTable>
my controller
public List<cContact> myContacts {get;set;}
public class cContact {
public Contact con {get; set;}
public boolean selected {get; set;}
public cContact(Contact c) {
con = c;
selected = false;
}
}
EDIT I also tried this
<apex:selectOptions value="{!items}" />
controller
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
for(cContact c :myContacts)
{
options.add(new SelectOption('',''));
}
return options;
}
but all the radio buttons were in one row.
apex:selectRadio
component works in this way, all it needs is aname
attribute. I'm not sure how they missed the ability to group radio buttons freely.