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
Sandy singhSandy singh 

On selectRadio Button selected value want to be access in apex class controller

Hi All,

 

 On selectRadio Button selected value want to be access in apex class controller.

 

Apex Code:

<apex:page controller="SelectRadioController">
<apex:form >
<apex:pageBlock >
<apex:selectRadio id="slctRd" dir="ltr" required="true" layout="pageDirection" value="{!selectedValue}" immediate="true">
<apex:selectOptions id="selRdOptn" value="{!Options}"/>
</apex:selectRadio>
<apex:outputText id="test" value="{!test}"></apex:outputText>
</apex:pageBlock>
</apex:form>
</apex:page>

 

controller Class:

public with sharing class SelectRadioController {
    
    public String selectedValue {get; set;}
    public List<SelectOption> Options {get; set;}
    
    public SelectRadioController() {
        Options = new List<SelectOption>();
        Options.add(new SelectOption('test1', 'test1'));
        Options.add(new SelectOption('test2', 'test2'));
        Options.add(new SelectOption('test3', 'test3'));
    }
    
   public String test{
     set{}
     get{
     test = 'Hello World' + selectedValue  ;
      return test;
     }
    }   
}

 

Here i want to display test filed on visualforce page, but this code is not working.

Can any one help me on this.

 

Thanks in Advance.

 

Ragards,

Sandesh

 

Best Answer chosen by Admin (Salesforce Developers) 
Chamil MadusankaChamil Madusanka

Try following changes

 

<apex:page controller="SelectRadioController">
<apex:form >
<apex:pageBlock >
<apex:selectRadio id="slctRd" dir="ltr" required="true" layout="pageDirection" value="{!selectedValue}" immediate="true">
<apex:actionSupport event="onchange" action="{!MethodOne}" reRender="test"/>
<apex:selectOptions id="selRdOptn" value="{!Options}"/>
</apex:selectRadio>
<apex:outputText id="test" value="{!test}"></apex:outputText>
</apex:pageBlock>
</apex:form>
</apex:page>

 

public with sharing class SelectRadioController {
    
    public String selectedValue {get; set;}
    public List<SelectOption> Options {get; set;}
	public String test{get;set;}
    
    public SelectRadioController() {
        Options = new List<SelectOption>();
        Options.add(new SelectOption('test1', 'test1'));
        Options.add(new SelectOption('test2', 'test2'));
        Options.add(new SelectOption('test3', 'test3'));
    }
    
   public void MethodOne() { test = 'Hello World' + selectedValue ; }
}

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

All Answers

Chamil MadusankaChamil Madusanka

Try following changes

 

<apex:page controller="SelectRadioController">
<apex:form >
<apex:pageBlock >
<apex:selectRadio id="slctRd" dir="ltr" required="true" layout="pageDirection" value="{!selectedValue}" immediate="true">
<apex:actionSupport event="onchange" action="{!MethodOne}" reRender="test"/>
<apex:selectOptions id="selRdOptn" value="{!Options}"/>
</apex:selectRadio>
<apex:outputText id="test" value="{!test}"></apex:outputText>
</apex:pageBlock>
</apex:form>
</apex:page>

 

public with sharing class SelectRadioController {
    
    public String selectedValue {get; set;}
    public List<SelectOption> Options {get; set;}
	public String test{get;set;}
    
    public SelectRadioController() {
        Options = new List<SelectOption>();
        Options.add(new SelectOption('test1', 'test1'));
        Options.add(new SelectOption('test2', 'test2'));
        Options.add(new SelectOption('test3', 'test3'));
    }
    
   public void MethodOne() { test = 'Hello World' + selectedValue ; }
}

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

This was selected as the best answer
Sandy singhSandy singh

Hi Chamil,

 

Thanks for your solution. it's perfeclty match with my requirement.

 

Regards,

Sandesh

Rashmi27Rashmi27

HI,

My problem situation is that I want to populate a customer 'site' based on the customer name selected by user on Visual Force Page. Here is the code :

<apex:page sidebar="false" showHeader="false" controller="LeadsController" >
<apex:form >
 <apex:pageBlock title="Leads Info">
<apex:pageMessages id="pgMsg" />
       <apex:pageblockSection title="Customer">   
              
        <apex:inputField required="true" value="{!lead.Customer__c}" id="customer" >
        <apex:actionSupport event="onchange" action="{!GetValue}" reRender="site"/>
        </apex:inputField>
                                           

                                 <apex:outputLabel title="Site:" value="Site"></apex:outputLabel>    
                         <apex:outputText value="{!SiteName}" id="site"> </apex:outputText>

                
                             </apex:pageblockSection>

<apex:pageBlockButtons >
        <apex:commandButton value="Add" action="{!Add}" />
        <apex:commandButton value="Notify" action="{!Notify}"/>

    </apex:pageBlockButtons>


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

 

The problem is that in the GetValue function in the controller, I try to use a select query where I pass 'lead.Customer__c' as a parameter to the where clause. However, lead.Customer__c will have the customer name only when i commit the lead obj to database. can you please tell me how can I access values of uncommitted visual force components (like inputfield) in Apex controller class?

 

thanks!