function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bdbagleybdbagley 

SelectRadio to return page Message?

So I've been playing around with selectRadio but I'm having trouble getting a page message to render on the selection of an account.  My original thought was to take a wrapper class and convert it into radio buttons instead of a pick list like others on this site, but I can't seem to get the right setup.  I then decided I would try and use a command link and param tag and see if it was possible to just add a selectradio component.  Needless to say I am completely new to this and I am using borrowed code and tutorials to teach myself this. From what I've read and understand at this point I believe I need to create an action function for the radio that changes the page message, but honestly I can't figue this out. Below is my code where the actual account names return a message, should I scrap this approach and try the wrapper class again?

 

<apex:page title="radiotest" controller="radiotest" sidebar="false">

  <apex:form >
 
      <apex:pageBlock title="Interview Five" id="Test">
         <apex:pageMessages > </apex:pageMessages>
        
          <apex:pageBlockTable value="{!Data}" var="acc">
            <apex:column >
                <apex:commandLink value="{!acc.name}" action="{!Calling}" reRender="Test">
                    <apex:param name="Txt" value="{!acc.id}"/>
                </apex:commandLink>
            </apex:column>
            <apex:column value="{!acc.Name}"/>
            <apex:column value="{!acc.BillingState}"/>
            <apex:column value="{!acc.Phone}"/>
            <apex:column value="{!acc.Website}"/>
        
          </apex:pageBlockTable>
      
      </apex:pageBlock>
  </apex:form>
 
</apex:page>

 

public class radiotest {
    public radiotest(){
 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,' Select an Account by Clicking its name.'));
 }
    List<Account> Varacc;
    public List<Account> getData()
    {
        string str1=Apexpages.currentpage().getParameters().get('id');
        Varacc =[Select id,Name,BillingState,Phone,Website from Account];      
        if(varacc.size()>0)
        {
            return Varacc;
        }
        return null;
    }
    public void Calling() {
        string str1=Apexpages.currentpage().getParameters().get('txt');
        Account varacc=[select id,name from Account where id=:str1];
        String ex=varacc.name;
        {
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,' You have Selected the '+varacc.name+' Account'));
        }
    }   
}

 Any help appreciated as I feel like I've exhausted all the reading material on the subjest but can't grasp it.

ibtesamibtesam

Try putting apex:pageMessages into an output panel and rerrender that output panel

bdbagleybdbagley

Sorry for never responding, I never saw the update and got busy working through HTTP requests. But I have the page message working if I want to simply click the account name; however, I'm having difficulty transfering this process to a radiobutton.  So I've been working with it some more but still having some issues.  Most of the documentaion on the subject refers to a drop down list with select options which is not what I'm looking to do so some direction would be nice. Below is where I'm at and I understand some of this is incorrect.  I've tried the selectradio option but I'm also looking into accomplishing this with html radiobutton. I have the layout correct, but I need to specify a value.

 

class:

public class interview8 {

    public String selectedValue {get; set;} //not sure what to do with the selected value in relation to selectoption below
    public List<SelectOption> Options {get; set;}
    public interview8() {

    }
    List<Account> Varacc;
    public List<Account> getData()
    {
        string str1=Apexpages.currentpage().getParameters().get('id');
        Varacc =[Select id,Name,BillingState,Phone,Website from Account];      
        if(varacc.size()>0)
        {
            return Varacc;
        }
        return null;
    }
    public void Calling() {
        string str1=Apexpages.currentpage().getParameters().get('txt');
        Account varacc=[select id,name,billingstate,phone,website from Account where id=:str1];
        String ex=varacc.name;
        {
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,' You have Selected the '+varacc.name+' Account'));
        }
    }   
}

 

page:

<apex:page title="Interview 8" controller="interview8" sidebar="false">

  <apex:form >
 
      <apex:pageBlock title="Interview Eight" id="Test">
         <apex:pageMessages id="message" > </apex:pageMessages>
        
 <table id="results" border="1">
                                      <tr>
                                            <th></th>
                                            <th>Name</th>
                                            <th>Billing State/Province</th>
                                            <th>Phone</th>                                           
                                            <th>Website</th>
                                      </tr>
                                <apex:repeat value="{!data}" var="acc">
                                    <tr>
                                        <td>
                                        <form>
                                            <apex:selectRadio id="slctRd" dir="ltr" required="true" value="{!selectedValue}" immediate="true">
                                            <apex:actionSupport event="onchange" action="{!Calling}" reRender="message"/>                                            
                                            <apex:selectOptions id="selRdOptn" value="{!Options}"/>                                             
                                            </apex:selectRadio>                                                              
                                        </form>
                                        </td>
                                        <td>{!acc.Name}</td>
                                        <td>{!acc.billingstate}</td>
                                        <td>{!acc.Phone}</td>
                                        <td>{!acc.Website}</td>
                                    </tr>
                                </apex:repeat>
                              </table>

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

 

<apex:page title="Interview 8" controller="interview8" sidebar="false">

  <apex:form >
 
      <apex:pageBlock title="Interview Eight" id="Test">
         <apex:pageMessages id="message" > </apex:pageMessages>
        
 <table id="results" border="1">
                                      <tr>
                                            <th></th>
                                            <th>Name</th>
                                            <th>Billing State/Province</th>
                                            <th>Phone</th>                                           
                                            <th>Website</th>
                                      </tr>
                                <apex:repeat value="{!data}" var="acc">
                                    <tr>
                                        <td>
                                        <form>
<apex:actionFunction action="{!Calling}" name="Save" rerender="Message"/>
<input type="radio" onclick=”Save()” > Click me to do the call</input>
<apex:param name="Param" assignTo="{!data}" value="?"/> //can't really find any documentation on this approach either
                                        </form>
                                        </td>
                                        <td>{!acc.Name}</td>
                                        <td>{!acc.billingstate}</td>
                                        <td>{!acc.Phone}</td>
                                        <td>{!acc.Website}</td>
                                    </tr>
                                </apex:repeat>
                              </table>

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

 

Alternate Page: