+ Start a Discussion

Bind data with the Repeat functionality form the controller to Visualforce page

//Data is getting append to the Html select tag, but not appending to the selectlist tag in saleforce.

Note: To use Repeat functionality only ..!

Visualforce page:
<apex:page controller="test12" >
<apex:form >
  Salesforce Selectlist:   
    <apex:selectList multiselect="false" size="1">
       <apex:selectOption ></apex:selectOption>
      <apex:repeat value="{!lstWrapper1}" var="a">
      <apex:selectOption itemLabel="{!a.Statename}" itemvalue="{!a.rating}" html-data-capitalname="{!a.capital}"></apex:selectOption>
    <br/> <br/>
   Html Selectlist:
 <apex:repeat value="{!lstWrapper1}" var="a">
    <option value="{!a.rating}" data-capitalname="{!a.capital}">{!a.statename}</option>

Apex class:
public class test12 {

     public  string selectedOption{get;set;} 
     public Wrapper Wrapper1{get;set;}
     public list<wrapper> lstWrapper1{get;set;}
  public test12(){
      lstWrapper1 = new list<wrapper>();
    string  jsonexample1 =  ' { "overalldata": [ {"stateName": "Andrapradesh",  "rating": "5.0" , "active": "yes" ,"Capital":"Amaravathi"}, { "stateName": "Telangana",  "rating": "4.0" ,"active": "no","Capital":"Hyderabad" }, {"stateName": "Karnataka",  "rating": "5.0" ,"active": "no","Capital":"Banglore"} , {"stateName": "Maharastra",  "rating": "4.5" ,"active": "no","Capital":"Mumbai"}] } ';

        Map<String, Object> mapobj1= (Map<String, Object>)JSON.deserializeUntyped(jsonexample1);
        system.debug('the Mapped and deserialized values are:'+ mapobj1); 
        Object objj1 = (object)mapobj1.get('overalldata');
        system.debug('the data value is :::'+objj1);
        string  SerilizeEmpdata1 = system.json.serialize(objj1);
    lstWrapper1 =(list<wrapper>)system.json.deserialize(SerilizeEmpdata1,list<wrapper>.class);
      public class Wrapper{
      public string  stateName{get;set;}
      public string  rating{get;set;}
      public string  active{get;set;}
      public string  Capital{get;set;}

After inspecting: it was binded to the html tag but not salesforce tag..

User-added image 

Hi @Deepikareddy,

You need to use <apex:selectOptions> instead of <apex:selectOption> and it will work for you. Please see the below link for its usage.


hi. Ikatney, i had used, but the thing is , In selectoptions we dnt have the Data-name attribute to append to the selectoptions .. jst by repeat functionality need to use the Selecitlist with Data-name as a attribute in the Selectoption Component ..!

Note: selectoptions is not accepting the parameter as the Data-attribute in salesforce..!
Thank you..!