Radio Button using input tag with type=radio in VF page and action support tag


VF Page: 
<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>
Controller:
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;
        }
     
    }

}

Code courtesy: Google.I don't remember the exact link of the site.But thanks for the unknown!!




Comments

Post a Comment

Popular posts from this blog

Embed Special Characters in VF Page

Error: Compile Error: Illegal conversion from String to System.PageReference

Some Common Errors in the Visual flow