1

I am building a page where I have contact's first name and Last Name as an input field. When I enter the first and last name, and click search all the cases related to the contact should display as a list having a radio button alongside them.

I go the cases related to the contact for a List<Case> excase{get;set;} variable in my extension and able to show it using apex:pageblocktable but now the challenge is how to show this List as a radio button in my VF page:

Here is part of my VF Page where I am writing the logic:

<apex:pageblocksection title="Search Exsisting Cases" columns="1">
      <apex:input label="Contact First Name" value="{!first}" id="firstnameid"/>
      <apex:input label="Contact Last Name" value="{!last}" id="lastnameid"/>
       <apex:pageblockTable value="{!excase}" var="exscase" id="caselist">
            <!-- <apex:selectradio value="{!exscase.CaseNumber}"></apex:selectradio>-->
            <apex:column value="{!exscase.CaseNumber}"/>
            <apex:column value="{!exscase.Status}"/>
            <apex:column value="{!exscase.Subject}"/>
       </apex:pageblockTable>

The case should be displayed with a radio button to select
        <apex:selectRadio value="{!excase}">

    </apex:selectRadio>  

    </apex:pageblocksection>




   <apex:pageBlockButtons location="bottom">
     <apex:outputPanel id="buttons1">
        <apex:commandButton action="{!search}" value="Search" id="SearchButton"/>
        <apex:commandButton action="{!updatecase}"  value="Update" id="NewCase"/>
     </apex:outputPanel>
   </apex:pageBlockButtons>
 </apex:pageBlock>

Part of logic from my controller extension:

  public List<Case> excase{get;set;}

    public Pagereference search(){

    excase=[Select Id,CaseNumber,Status,Subject from Case where contact.Name=:first +' '+ last];

    return null;
    }
1

You want to create a method in your controller that generates a selectOption list for your cases that you then pass to your page from your controller. Something like:

public static list<selectOption> getMyOptnsLst(){
   list<selectOption>MyOptnsLst = new list<selectOption>();
   for (Case c:excase){
     MyList.add(new selectOption(c.Id,c.Subject));
   {
   return MyOptnsLst
}

Once you have the above, you'd then create another Pageblock Section within a form tag that contains something like below:

<apex:form>
   <apex:selectRadio value="{!subject}">
      <apex:selectOptions value="{!MyOptnsLst}"/>
   </apex:selectRadio><p/>
   <apex:commandButton value="Select" action="{!selectCase}" />
</apex:form>

Your controller would also need a method named selectCase and a public variable named subject to hold the value of the selected radio button.

You simply loop through your select list until you find the one that matches in your method.

Edit

To get the radio buttons to appear in separate columns, you'll need to apply some CSS along with something like this:

 <apex:outputLabel value="{!MyOptionsLst}" for="theSelectRadio">
 </apex:outputLabel>

You can also add a <BR> tag at the end of each line which may solve your issue.

Alternatively, you could use an apex repeat or put this all in a PageBlockTable. There are a variety of ways to do this. If you use a table, put the label in one column aligned right and the select option in another aligned left.

  • Thanks. Is there way to show the Radio button in one column instead of showing it all in one row? – SfdcBat Apr 15 '16 at 18:20
  • 1
    Yes there is, use a label tag. Made some code correct there too. Apologies had them out of order. – crmprogdev Apr 15 '16 at 18:20
  • I used it as <apex:selectRadio label="CaseList" ... > , but it still appears in one row. How to write the syntax to get in one column? – SfdcBat Apr 15 '16 at 18:27
  • 1
    oh, I misread your comment. See my edits. Lots of options for doing this. – crmprogdev Apr 15 '16 at 18:36
  • Which one would be the simplest one? I am not sure if I made it clear that I would like each case in separate rows appearing in a list instead of showing all cases in one single row, side by side to each other(this is by default). – SfdcBat Apr 15 '16 at 18:45

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.