+ Start a Discussion
DeepikareddyDeepikareddy 

Datatable and Repeatfunctionality in salesforce

public class testclass5 {
 public list<wrapperclass> wrapclass{get;set;}
   public  testclass5(){
    wrapclass = new list<wrapperclass>();
    string  teststring= ' { "sucess":1,"data": [ {"stateName": "Andrapradesh",  "value": "apx" }, { "stateName": "Telangana",  "value":"tsx"}, {"stateName": "Banglore",  "value": "bngx"} , {"stateName": "Maharastra",  "value":"mhx" }  ] } ';

     Map<String, Object> maptest =   (Map<String, Object>) JSON.deserializeUntyped(teststring);
     
     system.debug(maptest); 
     
      Object ob = (Object)maptest.get('data');    
        System.debug(ob);
          
         String srlze  = System.JSON.serialize(ob); 
      system.debug(srlze);
       
   wrapclass  = (list<wrapperclass>)System.JSON.deserialize(srlze,list<wrapperclass>.class);
   system.debug(wrapclass);
  
  }
  
 public string selectedValue{get;set;}
 
   public pageReference testmethod1(){
    
     system.debug('for Datatable functionality:'+ selectedValue);
     return null;
   
   }
 
 public pageReference testmethod2(){
    
     system.debug('for repeat functionality:'+ selectedValue);
     return null;
   
   }
 

   public class wrapperclass{
   
    public string stateName{get;set;}
    
     public string  value{get;set;}
    
   }
   
   
 
}


Visualforce page:
 
<apex:page controller="testclass5">
 
  <apex:form >
    <apex:dataTable value="{!wrapclass}" var="a" cellpadding="6px">
    
    <apex:column > 
         <apex:actionsupport action="{!testmethod1}" event="onclick">
         {!a.stateName}<apex:param name="selectedValue" value="{!a.value}" assignTo="{!selectedValue}">
          </apex:param>
          </apex:actionsupport>
       </apex:column>
     
    </apex:dataTable>
    
    <br/>
    
      <apex:actionsupport action="{!testmethod2}" event="onclick">
    <apex:repeat value="{!wrapclass}" var="a" >
      <li style="padding:5px;"> 
    
         {!a.stateName}<apex:param name="selectedValue" value="{!a.value}" assignTo="{!selectedValue}">
          </apex:param>
          
      </li>
    </apex:repeat>
    
  </apex:actionsupport>
     
  
  
  </apex:form>
  
</apex:page>


after debugging iam getting the selectedvalue,as  null.., can anybody help to solve the issue. thank you... 
Best Answer chosen by Deepikareddy
Soyab HussainSoyab Hussain
Hi DeepikaReddy,
public class testclass5 {
    public list<wrapperclass> wrapclass{get;set;}
    public  testclass5(){
        wrapclass = new list<wrapperclass>();
        string  teststring= ' { "sucess":1,"data": [ {"stateName": "Andrapradesh",  "value": "apx" }, { "stateName": "Telangana",  "value":"tsx"}, {"stateName": "Banglore",  "value": "bngx"} , {"stateName": "Maharastra",  "value":"mhx" }  ] } ';
        
        Map<String, Object> maptest =   (Map<String, Object>) JSON.deserializeUntyped(teststring);
        
        system.debug(maptest); 
        
        Object ob = (Object)maptest.get('data');    
        System.debug(ob);
        
        String srlze  = System.JSON.serialize(ob); 
        system.debug(srlze);
        
        wrapclass  = (list<wrapperclass>)System.JSON.deserialize(srlze,list<wrapperclass>.class);
        system.debug(wrapclass);
        
    }
    
    public string selectedValue{get;set;}
    
    public pageReference testmethod1(){
        
        system.debug('for Datatable functionality:'+ selectedValue);
        return null;
        
    }
    
    public PageReference testmethod2(){
        system.debug('for repeat functionality:'+ selectedValue);
        return null;
    }
    
    public class wrapperclass{
        public string stateName{get;set;}
        public string  value{get;set;}
    }
    
    
    
}
 
<apex:page controller="testclass5">
    
    <apex:form id="frm" >
        <apex:actionFunction name="passValueToController" action="{!testmethod2}" reRender="frm">
            <apex:param name="selectedValue" value="selectedValue" assignTo="{!selectedValue}"></apex:param>
        </apex:actionFunction>
        <apex:repeat value="{!wrapclass}" var="a" >
            <li style="padding:5px;" onclick="passValueToController('{!a.value}'); return false;" > 
                {!a.stateName}
            </li>
        </apex:repeat>
    </apex:form>
    
</apex:page>


use this code may be this will help you to getting value.

Regards,
Soyab

All Answers

Soyab HussainSoyab Hussain
Hi DeepikaReddy,
public class testclass5 {
    public list<wrapperclass> wrapclass{get;set;}
    public  testclass5(){
        wrapclass = new list<wrapperclass>();
        string  teststring= ' { "sucess":1,"data": [ {"stateName": "Andrapradesh",  "value": "apx" }, { "stateName": "Telangana",  "value":"tsx"}, {"stateName": "Banglore",  "value": "bngx"} , {"stateName": "Maharastra",  "value":"mhx" }  ] } ';
        
        Map<String, Object> maptest =   (Map<String, Object>) JSON.deserializeUntyped(teststring);
        
        system.debug(maptest); 
        
        Object ob = (Object)maptest.get('data');    
        System.debug(ob);
        
        String srlze  = System.JSON.serialize(ob); 
        system.debug(srlze);
        
        wrapclass  = (list<wrapperclass>)System.JSON.deserialize(srlze,list<wrapperclass>.class);
        system.debug(wrapclass);
        
    }
    
    public string selectedValue{get;set;}
    
    public pageReference testmethod1(){
        
        system.debug('for Datatable functionality:'+ selectedValue);
        return null;
        
    }
    
    public PageReference testmethod2(){
        system.debug('for repeat functionality:'+ selectedValue);
        return null;
    }
    
    public class wrapperclass{
        public string stateName{get;set;}
        public string  value{get;set;}
    }
    
    
    
}
 
<apex:page controller="testclass5">
    
    <apex:form id="frm" >
        <apex:actionFunction name="passValueToController" action="{!testmethod2}" reRender="frm">
            <apex:param name="selectedValue" value="selectedValue" assignTo="{!selectedValue}"></apex:param>
        </apex:actionFunction>
        <apex:repeat value="{!wrapclass}" var="a" >
            <li style="padding:5px;" onclick="passValueToController('{!a.value}'); return false;" > 
                {!a.stateName}
            </li>
        </apex:repeat>
    </apex:form>
    
</apex:page>


use this code may be this will help you to getting value.

Regards,
Soyab
This was selected as the best answer
DeepikareddyDeepikareddy
it was helped thank you..