1

I am having a hard time to figure out how I can include the radio button select option within the PageBlockTable. I am searching all the cases related to a contact here.

Logic in my controller extension which gets all the cases where contact name match:

public List<Case> excase{get;set;}
public List<SelectOption> casesradio{get;set;}
public String radioValue{get;set;}
public Pagereference search() {
  excase = [Select Id, CaseNumber, Status, Subject from Case where contact.Name = : first + ' ' + last];
  for (Case cd: excase) {
   casesradio.add(new SelectOption(cd.Id, cd.Subject));
  }

  return null;
 }

I use PageblockTable tag to show it on the Page:

    <apex:pageblockTable value="{!excase}" var="exscase" id="caselist">
       <apex:column value="{!exscase.CaseNumber}"/>
       <apex:column value="{!exscase.Status}"/>
       <apex:column value="{!exscase.Subject}"/>
    </apex:pageblockTable>

I would also like user to select a particular case and update it.(My update has some logic which is irrelevant for this question). I use below code to show the cases as radio button selectOption:

    <apex:selectRadio label="Select Case to Update" value="{!radioValue}">
       <apex:selectOptions value="{!casesradio}"/>
    </apex:selectRadio>

This appears in a single line as shown in screenshot. My logic in extension for select option is(same as above):

public List<Case> excase{get;set;}
public List<SelectOption> casesradio{get;set;}
public String radioValue{get;set;}
public Pagereference search() {
  excase = [Select Id, CaseNumber, Status, Subject from Case where contact.Name = : first + ' ' + last];
  for (Case cd: excase) {
   casesradio.add(new SelectOption(cd.Id, cd.Subject));
  }

  return null;
 }

enter image description here

I am trying to get the radio button for each row in PagebLockTable as show in the screen shot. I would like to select the radio button and pass the selected case back to my extension when I click update. How can the code be modified to accomplish this.

3
  • 6
    This is a textbook use case for a wrapper class. A quick search of SFSE will give you lots of examples. Here's one from salesforce: developer.salesforce.com/page/Wrapper_Class
    – Mark Pond
    Apr 17, 2016 at 19:37
  • Is there any example where radio selectoption is used? If you see in my extension I am creating a list called caseradio. How can I use this as page blocktable value since page blocktable has already a value which displays list of cases.
    – SfdcBat
    Apr 17, 2016 at 19:51
  • 3
    Your pageblocktable will be bound to a list of the wrapper class (cContact in the linked example) instead of a list of Case. Each one of those wrappers will have a Case record "inside" it (con in the linked example).
    – Mark Pond
    Apr 17, 2016 at 20:01

1 Answer 1

3

Few days back I also have same problem. To resolve I use below steps:

  1. I created an inner class in which I store the name (Label of Radio button).

    class ContactName { String name; }

  2. Create a list of inner class and assign values to them.

    List<ContactName> cName = new List<ContactName>(); cName.add('This is a new case'); cName.add('This is old Case');

  3. on VF Page, use html radio button tag in outputPanel

<apex:pageBlockTable value="cName" var="cs"> <apex:outputPanel> <input type="radio" name="caseName"> <label>{!cs.name}</label> </apex:outputPanel> </apex:pageBlockTable>

It will helps you.

1
  • Thanks. My pageblockTable has a value already from where I get list of Cases. public List<Case> excase{get;set;} , If I replace it with ContactName class then I would not be able to show Case in my table. I have read through the link given by Mark Pond above and It suggest to create a wrapper class. I did so and I was able to get the radio button for each cases, however there is an issue for which I posted a question. Can you assist me with that question?
    – SfdcBat
    Apr 18, 2016 at 5:47

You must log in to answer this question.

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