function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DeepikareddyDeepikareddy 

How to append data form the Controller to Selectlist using the REPEAT TAG

APEXCLASS:

i have got the class and derserilized to the respective Class, now need to append the data to the picklist using the Selectlist  using the Repeat Functionality...!


 

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);
        system.debug(SerilizeEmpdata1);
    lstWrapper1 =(list<wrapper>)system.json.deserialize(SerilizeEmpdata1,list<wrapper>.class);
     system.debug(lstWrapper1);
       
       
    
  
      public class Wrapper{
      public string  stateName{get;set;}
      public string  rating{get;set;}
      public string  active{get;set;}
      public string  Capital{get;set;}
      
      
      
      }
}
 

Need to Append the data using the Repeat functionality to selectoption in salesforce
 

<apex:page controller="test12" >
 
<apex:form >

           
            
    <apex:selectList multiselect="false" size="1">
     <apex:repeat value="{!lstWrapper1}" var="a" >

    <!--showing an error while appending to the select option--->
  </apex:repeat>
     
    </apex:selectList>
    
     
</apex:form>
 
</apex:page>
 


Note:
 <apex:selectoption  itemlabel ="{!lstwrapper.name}"  and itemvalue= "{!lstwrapper.rating}" html-data-capitalname ="{!lstwrapper.capitalname}" />

//how it can be acheived....

Thanks 
Deepika Reddy...

 

FARSANA PSFARSANA PS
Hai Deepika,

Try this eg,

http://www.infallibletechie.com/2014/04/difference-between-apexselectoption-and.html

If we are sure about the values, we can make use of apex:selectOption and If we are unsure about the values, we can make use of apex:selectOptions and we can fetch the values from our controller.

Use apex:selectOptions  insted of repeat  apex:selectOption

Try this eg:
 
<apex:page controller="displayMessage"> 
<apex:form >      

<apex:selectList value="{!SelectedOption}"  size="1" multiselect="false">
            <apex:selectOptions value="{!items}"/>
        </apex:selectList>

</apex:form>
</apex:page>

public class test12{
    
    public  string selectedOption{get;set;} 
    public Wrapper Wrapper1{get;set;}
    public list<wrapper> lstWrapper1{get;set;}

    public  displayMessage(){
        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);
        system.debug(SerilizeEmpdata1);
        lstWrapper1 =(list<wrapper>)system.json.deserialize(SerilizeEmpdata1,list<wrapper>.class);
        system.debug(lstWrapper1);  
    }  
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('none','--select--'));
        For(Wrapper lw :lstWrapper1)
            options.add(new SelectOption(lw.stateName,lw.stateName));
        return options;
    }
    public class Wrapper{
        public string  stateName{get;set;}
        public string  rating{get;set;}
        public string  active{get;set;}
        public string  Capital{get;set;}
    }
}

Hope this helps..
 
DeepikareddyDeepikareddy
hi.. Farsana, thanks for your reply, the solution you had done is good, but the thing is
1) I need to bind the data-attribute to selectoption tag .
 
<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>
      </apex:repeat>
    </apex:selectList>
    
    <br/> <br/>
   
   Html Selectlist:
    <select>
 <apex:repeat value="{!lstWrapper1}" var="a">
    <option value="{!a.rating}" data-capitalname="{!a.capital}">{!a.statename}</option>
    
    </apex:repeat>         
         </select>
     
</apex:form>
 
</apex:page>

//the data is binding to the html code, but it is unable to bind to the Salesforce Selectlist, ..! as shown in the image


User-added image

//data is getting append to the html select tag,  but not appending to the Salesforceselectlist