I'm creating a VF page on Opportunity Products where I have an apex:repeat and inside the repeat, I have a picklist that gets it's values from a SOQL query on a related object. I have no problem populating that list but what I can't figure out is how get the values out of every picklist inside the repeat into my controller method and update the original record with those values.
For example, I want Opportunity Product[0] to have its' competitor set as the value from the picklist besides that product name, Opportunity Product[1] with that value etc. Here, competitors are fetched with SOQL query to a custom object. To map the values correctly, that's where I'm stumped. Would using a Map be efficient, where id put into the map the OpportunityProductId and competitor value so I can map the selected value from the picklist to the correct product?
Controller:
Page:
<apex:page controller="VF_compList">
<apex:form >
<apex:pageBlock >
<table>
<th>Product name</th><th>Competitor</th>
<div align="left">
<apex:repeat value="{!products}" var="prods" rendered="true">
<tr>
<div align="left">
<apex:outputText value="{!prods.name}" id="theValue"/><br/>
</div>
<div align="right">
<apex:selectList id="dropdown" multiselect="false" size="1">
<apex:selectOptions value="{!Competitors}">
</apex:selectOptions>
</apex:selectList>
</div>
</tr>
</apex:repeat>
</div>
</table>
</apex:pageBlock>
<apex:commandButton action="{!submit}" id="theButton"/>
</apex:form>
</apex:page>
controller:
public class VF_compList {
public VF_compList(){}
public Id gId = ApexPages.currentPage().getParameters().get('gId');
Opportunity o = [SELECT id from Opportunity where Id =:gId];
Map<Id,String> prodMap = new Map<Id,String>();
public List<SelectOption> comps {get;set;}
public List<OpportunityLineItem> olist {get;set;}
public List<Opportunity_Competitor__c> competitorsList {get;set;}
String[] tempstring {get;set;}
public void setCompetitorsOnKeyup(){
}
public List<SelectOption> getCompetitors(){
system.debug('gId is: '+gId);
competitorsList = [SELECT Name, Competitor__r.Name from
Opportunity_Competitor__c where Opportunity__c =:o.Id];
List<SelectOption> values = new List<SelectOption>();
for(Opportunity_Competitor__c a:competitorsList){
SelectOption b = new
SelectOption(a.Competitor__r.Name,a.Competitor__r.Name);
values.add(b);
//comps.add(b);
}
return values;
}
public List<OpportunityLineItem> getProducts(){
olist = [SELECT Id, Name,txCompetitors__c from OpportunityLineItem where
OpportunityId =:o.Id];
return oList;
}
public void submit(){
for(OpportunityLineItem e:olist){
//e.txCompetitors__c = ?
}
}
}