1

I have simple custom page:

<apex:page controller="opportunityList2Con">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!employees}" var="o" >
        <apex:column >
        <apex:selectRadio value="{!o.Name}" label="Select"/>
        </apex:column>
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.Email__c}"/>
            <apex:column value="{!o.Annual_salary__c}"/>

            </apex:pageBlockTable>
    </apex:pageBlock>
    <apex:commandButton action="{!view}" value="View" id="theViewButton" />
    <apex:commandButton action="{!edit}" value="Edit" id="theEditButton"/>


</apex:form>
</apex:page>

Unfortunately I am able to select more then one row in a list(so it behaves more like checkbox then radiobutton). Do you know how can i resolve this problem?

Thanks

2
  • 1
    many of the solutions that sfdcfox suggest use inputCheckBox as the component but styled as a radio button; controller code, javascript, or jQuery is required to enforce the semantics of the radio button
    – cropredy
    Oct 7 '15 at 19:44
  • 1
    Because the elements of the selectRadio are in different rows of the table, SFDC gives them name attributes that include the row index in order to make them unique in the DOM when they are rendered. Unfortunately, that has the side effect of breaking the feature where all radio input elements with the same name value are "grouped" by the browser allowing you to only select one of the radio buttons with that name.
    – Mark Pond
    Oct 7 '15 at 22:45
2

selectRadio renders a List<SelectOption> as a series of radio options. You cannot render the radio group across multiple rows. In terms of code, it is rendered as a table with one option in each cell; you can specify if the table goes across or down, but that table will be contained in a single row in the enclosing page block table (a single cell, in other words). To make a single selectable option out of a number of rows on a page block table, you'll need JavaScript or additional server-side code. You can find tons of examples of how to this with jQuery all over the web.

2
  • Understand. Can I in this situation select a row on from my list? Or also no?
    – k4sia
    Oct 7 '15 at 19:42
  • @k4sia Using JavaScript or some other technique, yes.
    – sfdcfox
    Oct 7 '15 at 19:52
1

If you want to select one single radio for complete record then you can try this approach

<apex:page controller="opportunityList2Con">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!employees}" var="o" >
        <apex:column >
        <apex:selectRadio html-name="table" value="{!o.Name}" label="Select"/>
        </apex:column>
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.Email__c}"/>
            <apex:column value="{!o.Annual_salary__c}"/>

            </apex:pageBlockTable>
    </apex:pageBlock>
    <apex:commandButton action="{!view}" value="View" id="theViewButton" />
    <apex:commandButton action="{!edit}" value="Edit" id="theEditButton"/>


</apex:form>
</apex:page>

It will work for you and will solve the problem

2
  • Thanks for your reply but I still can select more then one row
    – k4sia
    Oct 8 '15 at 11:44
  • Check in console if name attribute is still there. i think salesforce removed it. You need to add this tag using jquery or Javascript(if possible) Oct 8 '15 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.