You need to sign in to do that
Don't have an account?
Abhishek Singh 88
how get selected radiobutton value in constructor
Hi All,
I have a vf page which have two radio button Yes or No. I want selected value in constructor after clicking on submit buton.
here is code.
Since in the exisitng contrroler most of the logic is implemented in constructor. And now i have to add condition
IF(selected value=='Yes')
{
//code
}
else
{
// code
}
I have a vf page which have two radio button Yes or No. I want selected value in constructor after clicking on submit buton.
here is code.
<apex:page controller="CCO_ScheduleACallController"> <apex:form > <apex:pageBlock > <apex:outputLabel style="Bold">Are you able to launch your software or service?</apex:outputLabel> <apex:selectRadio value="{!radiovalue}"> <apex:selectOption itemLabel="Yes" itemValue="1"></apex:selectOption> <apex:selectOption itemLabel="No" itemValue="2"></apex:selectOption> </apex:selectRadio> <apex:pageBlockButtons location="bottom"> <apex:commandButton action="{!Submit}" value="Submit"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
Since in the exisitng contrroler most of the logic is implemented in constructor. And now i have to add condition
IF(selected value=='Yes')
{
//code
}
else
{
// code
}
As constructor will be executed on page load, and constructor will execute only once when we create instance for the class. You cannot achieve above mentioned functionality using constructor, instead use separate method which will execute when you change the options.
Please find below example Please let me know, if you need more information.
Best Regards,
Dayakar.D
Please try the below code. Hope this helps you.
//VF Page
<apex:page controller="TestSelectedOptionClass">
<apex:form >
<apex:pageBlock >
<apex:outputLabel style="Bold">Are you able to launch your software or service?</apex:outputLabel>
<apex:selectRadio value="{!selectedValue}">
<apex:selectOption itemLabel="Yes" itemValue="1"></apex:selectOption>
<apex:selectOption itemLabel="No" itemValue="2"></apex:selectOption>
<apex:actionSupport event="onchange" action="{!checkSelectedValue}" reRender="none"/>
</apex:selectRadio>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!Submit}" value="Submit"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
//Controller Class
public class TestSelectedOptionClass {
public String selectedValue { get; set; }
public TestSelectedOptionClass(){
// Here initializing the variable. If you want to preselect some radio button
// just assign it value to the variable here (eg. selectedValue = '1';)
selectedValue = '';
}
public void checkSelectedValue(){
system.debug('Selected value is: ' + selectedValue);
}
public static void Submit()
{
}
}
The above code will return itemValue in SelectedValue variable .Then you can able to write your condition like this.
IF(selected value=='1')
{
//code
}
else
{
// code
}
Please mark it as best answer if you find helpful.
Thank You
Ajay Dubedi