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
mustafatopmustafatop 

How to use apex:selectlist into apex:repeat?

s and s2 variables don't set selected value that is come from piclist in vf page when I use apex:selectlist tag in apex:repeat tag. So s and s2 are always '09:00'. When I remove apex:repeat tag, the problem is solved. But I need it.

 

How to solve this problem without save button into apex:repeat tag?

 

 A piece of the the my code is following.

     String s = '09:00';
     String s2 = '09:00';
     
     public String getSelectedItem(){
          return s;
     }
     public void setSelectedItem(String s){
         this.s = s;
     }
     
     public String getSelectedItem2(){
          return s2;
     }
     public void setSelectedItem2(String s2){
         this.s2 = s2;
     }

     public List<SelectOption> getItems(){
            List<SelectOption> options = new list<SelectOption>();
            String mins = '30';
            for (Integer i = 0; i < 48; i++) 
            {
                mins        = (mins == '30') ? '00' : '30';
                Integer hrs = ((i*30) / 60);
                String hr   = (string.valueOf(hrs).length() == 1) ? '0' + string.valueOf(hrs) : string.valueOf(hrs);            

                String key = hr + ':' + mins;
   
                options.add(new SelectOption(key, key));
            }
            return options;      
     }
 

 

                <apex:repeat value="{!events}" var="itr">
                    <br/><br/>     
                    
                    <table>            
                        <tr>        
                            <td><apex:inputfield value="{!itr.Subject}" id="subject"/></td><td>
                            <apex:inputfield value="{!itr.IsAllDayEvent}" id="day"/></td><td>
                            <apex:inputfield value="{!itr.StartDateTime}" id="start"/></td><td>
                            <apex:selectlist value="{!SelectedItem}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.EndDateTime}" id="end"/></td><td>
                            <apex:selectlist value="{!SelectedItem2}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.Status__c}" id="status" /></td><td>
                            <apex:inputField value="{!itr.Type__c}" id="type"/></td><td>
                            <apex:inputField value="{!itr.Consultancy_Duration__c}" id="duration"/></td><td>
                            <apex:inputField value="{!itr.Project_Phase__c}" id="phase"/></td><td>
                            <apex:inputField value="{!itr.Location}" id="location"/></td><td>
                            <apex:inputField value="{!itr.Description}" id="description"/></td>
                        </tr>    
                    </table>
                                         
               </apex:repeat>
                                
                   <br/><br/>
                
                <p align="center"><apex:commandButton action="{!save}" value=" Save " /></p>

 

URVASHIURVASHI

hey have u got the solution to the problem as i am also facing the same issue.?

Please help if u have solution.

mustafatop10mustafatop10

Unfortunately, I could not find a solution, given up on using repeat tag. And 10 times to repeat the all inputfields without repeat tag. Maybe you use to <apex:variable> tag for its work.

URVASHIURVASHI

i want to repeat the select list 'n' number of times.will <apex:variable> tag work?

mustafatop10mustafatop10

I'm not sure becuase I haven't tried this, I said maybe you can try.

 

following codes are not the solution that you're looking for but maybe give an idea you.

 

<apex:form >
        <apex:outputPanel id="eventPage">
            <apex:pageMessages />
            <apex:pageBlock mode="edit">
                <apex:pageBlockSection title=""/>
                <apex:variable var="e" value="{!e}"/>
                <apex:variable var="e1" value="{!e1}"/>
                <apex:variable var="e2" value="{!e2}"/>
                <apex:variable var="e3" value="{!e3}"/>
                <apex:variable var="e4" value="{!e4}"/>
                <apex:variable var="e5" value="{!e5}"/>
                <apex:variable var="e6" value="{!e6}"/>
                <apex:variable var="e7" value="{!e7}"/>
                <apex:variable var="e8" value="{!e8}"/>
                <apex:variable var="e9" value="{!e9}"/>
                <apex:variable var="e10" value="{!e10}"/>
...
...
<table>
<tr>
<td style="font-weight:bold;">1</td> 
<td><input type="text" id="j_id0:j_id2:j_id30:j_id553" onchange="updateSubjects(this); updateSubjects2(this);"/></td>
<td><apex:inputfield value="{!e1.DateField__c}" onchange="updateDate(this)"/></td>
<td> 
<apex:selectlist value="{!selectedItem1}" size="1" id="i1">
<apex:selectOptions value="{!Items}"/>
</apex:selectlist>
</td>
<td>
<apex:selectlist value="{!selectedItem2}" size="1" id="i2">
<apex:selectOptions value="{!Items}"/>
</apex:selectlist>
</td> 
<td><apex:inputField value="{!e1.Type__c}"/></td>
<td><apex:inputField value="{!e1.Consultancy_Duration__c}"/> </td>
<td><apex:inputField value="{!e1.Project_Phase__c}"/></td>
<td><apex:inputField value="{!e1.Location}" onchange="updateInput(this);"/></td>
<td><apex:inputField value="{!e1.Description}"/> </td> 
</tr> 
<tr>
<td style="font-weight:bold;">2</td>
<td><input type="text" id="j_id0:j_id2:j_id30:j_id576" onchange="updateSubjects2(this);"/></td>
<td><apex:inputfield value="{!e2.DateField__c}" onchange="updateDate(this)"/></td>
<td>
<apex:selectlist value="{!selectedItem3}" size="1" id="i22">
<apex:selectOptions value="{!Items}"/>
</apex:selectlist>
</td>
<td>
<apex:selectlist value="{!selectedItem4}" size="1" id="i23">
<apex:selectOptions value="{!Items}"/>
</apex:selectlist>
</td>
<td><apex:inputField value="{!e2.Type__c}"/></td>
<td><apex:inputField value="{!e2.Consultancy_Duration__c}"/> </td>
<td><apex:inputField value="{!e2.Project_Phase__c}"/></td>
<td><apex:inputField value="{!e2.Location}" /></td>
<td><apex:inputField value="{!e2.Description}"/> </td> 
</tr>
.
.
.
<tr>
<td style="font-weight:bold;">10</td>
<td><input type="text" id="j_id0:j_id2:j_id30:j_id760" onchange="updateSubjects2(this);"/></td>
<td><apex:inputfield value="{!e10.DateField__c}" onchange="updateDate(this)"/></td>
<td>
<apex:selectlist value="{!selectedItem19}" size="1" id="i190">
<apex:selectOptions value="{!Items}"/>
</apex:selectlist>
</td>
<td>
<apex:selectlist value="{!selectedItem20}" size="1" id="i191">
<apex:selectOptions value="{!Items}"/>
</apex:selectlist>
</td>
<td><apex:inputField value="{!e10.Type__c}"/></td>
<td><apex:inputField value="{!e10.Consultancy_Duration__c}"/> </td>
<td><apex:inputField value="{!e10.Project_Phase__c}"/></td>
<td><apex:inputField value="{!e10.Location}" /></td>
<td><apex:inputField value="{!e10.Description}"/> </td> 
</tr>

 

 public List<String> selectedItems;
    public String selectedItem1{get;set;}
    public String selectedItem2{get;set;}
    public String selectedItem3{get;set;}
    public String selectedItem4{get;set;}
    public String selectedItem5{get;set;}
    public String selectedItem6{get;set;}
    public String selectedItem7{get;set;}
    public String selectedItem8{get;set;}
    public String selectedItem9{get;set;}
    public String selectedItem10{get;set;}
    public String selectedItem11{get;set;}
    public String selectedItem12{get;set;}
    public String selectedItem13{get;set;}
    public String selectedItem14{get;set;}
    public String selectedItem15{get;set;}
    public String selectedItem16{get;set;}
    public String selectedItem17{get;set;}
    public String selectedItem18{get;set;}
    public String selectedItem19{get;set;}
    public String selectedItem20{get;set;}

    public List<SelectOption> getItems(){
        List<SelectOption> options = new list<SelectOption>();
        String mins = '30';
        for (Integer i = 0; i < 48; i++){
            mins = (mins == '30') ? '00' : '30';
            Integer hrs = ((i*30) / 60);
            String hr   = (string.valueOf(hrs).length() == 1) ? '0' + string.valueOf(hrs) : string.valueOf(hrs);            
            String key = hr + ':' + mins;
            options.add(new SelectOption(key, key));
        }
        return options;      
     }

.
.
.

 

URVASHIURVASHI

No this code isnt useful for me.

As i don want input field associated with my code.

I want to create a selectlist listbox ' n' times where 'n' is the value from controlller.

So i had used selectlist within repeat tag and achieved it.

but now i am not able to get the value for selectlist which i select.

IF you any other solution please help.

 

THis link is similar case:

http://salesforce.stackexchange.com/questions/11965/apexselectlist-value-not-getting-set-in-controller/12212#

 

but i am not understanding what is done in it.

 

THanks.