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
TLFTLF 

Can't Use apex:repeat to build a selectList

Hi,

 

Maybe I'm missing something, but I'm having a problem using the apex:repeat tag to build a selectList control on my page. Here is the code:

 

<apex:selectList size="1" value="{!myOrder.DeliveryMethod__c}" >
<apex:selectOption itemValue="" itemLabel="-- None --" />

<apex:repeat value="{!deliveryMethods}" var="item">

<apex:selectOption itemValue="{!item}" itemLabel="{!item}" />

</apex:repeat>

</apex:selectList>

 

 

I know by inserting debug code into my page that the deliveryMethods collection has the values I want. But, the resulting selectList contains only the option that I added explicitly. Why am I unable to build the selectList using a repeat? Seems like a bug to me.

 

I know someone out there is going to suggest that I use an apex:selectOptions component, bound to a List<SelectOption> in my controller. Unfortunately I can't do that because this code resides within an apex:component, and I cannot pass a SelectOption[] as an attribute to my component. 

Best Answer chosen by Admin (Salesforce Developers) 
wesnoltewesnolte

Hey

 

You will need to use selectOptions as you suggested. I'm not sure of your exact issue, but you can use a controller on the component and that controller could initialise a list<selectOption> using data passed as an attribute. You could then use a method of teh component controller to return this list.

 

Another option is passing the component an apex class, and have a method to return the selectoptions in there. I haven't tried doing this before but the documentation says you should be able to do it.

 

Cheers,

Wes