/*
Here i want to demonstrate vf page with radio button on standard object USER and selected value will be save in custom object (TestUser__c )
*/
/*--------------------------------------------------------------------------------------------
Controller code
----------------------------------------------------------------------------------------------*/
public with sharing class UserTestController {
Public List<User> uList{get;set;}
Public Id str {get;set;}
Public Boolean flag {get;set;}
public UserTestController(ApexPages.StandardController controller) {
flag = true;
uList =[select Name, id from User where IsActive = true Limit 3];
}
public PageReference process(){
System.debug('----------'+str);
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'Required Id Is:::::'+str);
ApexPages.addMessage(myMsg);
flag = false;
return null;
}
public PageReference Save(){
flag =true;
System.debug('----------Save'+str);
if(str != null){
TestUser__c tUser = new TestUser__c();
tUser.User__c = str;
insert tUser ;
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'User Successfully Saved');
ApexPages.addMessage(myMsg);
return null;
}
else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Error,'Please select USER');
ApexPages.addMessage(myMsg);
return null;
}
}
}
/*--------------------------------------------------------------------------------------------
VF page code
----------------------------------------------------------------------------------------------*/
<apex:page standardController="User" extensions="UserTestController">
<apex:form >
<apex:pageblock >
<apex:outputPanel id="ca"><apex:pageMessages /></apex:outputPanel>
<apex:outputPanel id="counter">
<table cellpadding="7" cellspacing="7" border="1">
<th>Select</th>
<th> User Name</th>
<th>Id</th>
<apex:repeat value="{!uList}" var="v">
<tr>
<td>
<apex:outputPanel id="counter2">
<input type="radio" name="sel" />
<apex:actionsupport event="onchange" action="{!process}" rerender="ca,abc">
<apex:param name="select" value="{!v.id}" assignTo="{!str}"/>
</apex:actionsupport>
</apex:outputPanel>
</td>
<td>
<apex:outputText value="{!v.Name}"/>
</td>
<td>
<apex:outputText value="{!v.id}"/>
</td>
</tr>
</apex:repeat>
</table>
<apex:commandButton value="Save" action="{!Save}" disabled="{!flag}" id="abc"/>
</apex:outputPanel>
</apex:pageblock>
</apex:form>
</apex:page>
Here i want to demonstrate vf page with radio button on standard object USER and selected value will be save in custom object (TestUser__c )
*/
/*--------------------------------------------------------------------------------------------
Controller code
----------------------------------------------------------------------------------------------*/
public with sharing class UserTestController {
Public List<User> uList{get;set;}
Public Id str {get;set;}
Public Boolean flag {get;set;}
public UserTestController(ApexPages.StandardController controller) {
flag = true;
uList =[select Name, id from User where IsActive = true Limit 3];
}
public PageReference process(){
System.debug('----------'+str);
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'Required Id Is:::::'+str);
ApexPages.addMessage(myMsg);
flag = false;
return null;
}
public PageReference Save(){
flag =true;
System.debug('----------Save'+str);
if(str != null){
TestUser__c tUser = new TestUser__c();
tUser.User__c = str;
insert tUser ;
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'User Successfully Saved');
ApexPages.addMessage(myMsg);
return null;
}
else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Error,'Please select USER');
ApexPages.addMessage(myMsg);
return null;
}
}
}
/*--------------------------------------------------------------------------------------------
VF page code
----------------------------------------------------------------------------------------------*/
<apex:page standardController="User" extensions="UserTestController">
<apex:form >
<apex:pageblock >
<apex:outputPanel id="ca"><apex:pageMessages /></apex:outputPanel>
<apex:outputPanel id="counter">
<table cellpadding="7" cellspacing="7" border="1">
<th>Select</th>
<th> User Name</th>
<th>Id</th>
<apex:repeat value="{!uList}" var="v">
<tr>
<td>
<apex:outputPanel id="counter2">
<input type="radio" name="sel" />
<apex:actionsupport event="onchange" action="{!process}" rerender="ca,abc">
<apex:param name="select" value="{!v.id}" assignTo="{!str}"/>
</apex:actionsupport>
</apex:outputPanel>
</td>
<td>
<apex:outputText value="{!v.Name}"/>
</td>
<td>
<apex:outputText value="{!v.id}"/>
</td>
</tr>
</apex:repeat>
</table>
<apex:commandButton value="Save" action="{!Save}" disabled="{!flag}" id="abc"/>
</apex:outputPanel>
</apex:pageblock>
</apex:form>
</apex:page>