You need to sign in to do that
Don't have an account?
How can I get value of Apex:SelectRadio in then Apex:DynamicComponent
Hello,
I can not get value from Apex:SelectRadio in the Apex:DynamicComponent.
This is example my code:
public with sharing class Sample{
public List<showsample> listcountry {get;set;}
public Sample()
{
//Create new List when loading page
listcountry = new List<showsample>();
listcountry.add(new showsample());
listcountry.add(new showsample());
}
public Component.Apex.OutputPanel getSelectRadio()
{
Component.Apex.OutputPanel opSelectRadio = new Component.Apex.OutputPanel();
opSelectRadio.id='opSelect';
If(listcountry.size() > 0)
{
//Create SelectRadio component
For(showsample item: listcountry)
{
Component.Apex.selectRadio radio = new Component.Apex.selectRadio();
radio.expressions.value = '{!item.Text}';
radio.childComponents.add(getSelectOption('US','US'));
radio.childComponents.add(getSelectOption('CANADA','Canada'));
radio.childComponents.add(getSelectOption('MEXICO','Mexico'));
opSelectRadio.childComponents.add(radio);
}
}
return opSelectRadio;
}
Private component.apex.selectOption getSelectOption(String label,String value)
{
component.apex.selectOption opt=new component.apex.selectOption();
opt.itemLabel = label;
opt.itemValue = value;
return opt;
}
public PageReference Save()
{
If(listcountry.size() > 0)
{
For(showsample item: listcountry)
{
system.debug('Show Contry content: ' + country);
}
}
return null;
}
//defined Class entry
private class showsample
{
public showsample(){}
Public String Text {get;set;}
}
}
==========================End Controller==================================
=====================VisualForce Page===============================================
<apex:page controller="Sample">
<apex:form >
<apex:outputPanel id="out2" >
<apex:dynamicComponent componentValue="{!SelectRadio}"/> //call DynamicComponent
</apex:outputPanel>
<apex:actionFunction action="{!Save}" name="save" id="save" reRender="opSelect"/>
<script>
function savemethod()
{
save();
}
</script>
<input type="button" value="Save" onclick="savemethod();" /> // run save funtion
</apex:form>
</apex:page>
=====================End VisualForce Page===============================================
* I loaded page ok and after that select on each radio button 'US' or 'Canada' => click Save button
The result is here: Null
The result is here: Null
Expect Result is: 'Us' or 'Canada'
Please help me and check what is my wrong!.
Thanks,
Dat thep soft