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
Jeremy DeseezJeremy Deseez 

Get all SelectOptions values from each row on a table.

Hello,
I have a table with multiple rows, and a selectoptions for each row.
When I have only one row, I can get the value (fol.Type__c = typeOfOpp;) in my controller, but if there is many rows, the value is "none".

Apex Code : 
public String typeOfOpp{get;set;}

public List<SelectOption> loadFastType(){
		fastType = new List<SelectOption>();
		fastType.add(new SelectOption('none', '-- Select Type --'));
		fastType.add(new SelectOption('Optimist', 'Optimist'));
		fastType.add(new SelectOption('Forecast Exit', 'Forecast Exit'));
		fastType.add(new SelectOption('Pessimist', 'Pessimist'));
		return fastType;
	}

public void saveValue(){
		List<FAST_OPP__c> fastOppListToSave = new List<FAST_OPP__c>();
		for(FAST_OPP__c fol : fastOppList){
			fol.Opp_ID__r = null;
			fol.Type__c = typeOfOpp;
			fastOppListToSave.add(fol);
		}
		try {
			//upsert fastOppList;
			upsert fastOppListToSave;
		} catch (exception ex) {
			System.debug(ex);
		}
	}


Kind regards
Glyn Anderson 3Glyn Anderson 3
Need more information.  Can you post the VF markup for the table?  Is it a pageBlockTable?  What collection does the table iterate over?  If it is a collection of sObjects, you probably need to use a wrapper class, which would allow you to track the "typeOfOpp" value for each row separately, rather than using one variable.  If you post your table markup, I might be able to show you how to modify it.
Jeremy DeseezJeremy Deseez
Hello, thanks for your help.
It's a pageBlockTable, and the information come from a Custom Object.
VF Page : 
<apex:pageBlock>
	<apex:pageBlockTable value="{!fastOppList}" id="table" var="f" >
				<apex:column headerValue="Opportunity Name" value="{!f.Opp_ID__c}"/>
				<apex:column headerValue="Amount" styleClass="amount_to_copy" value="{!f.Opp_Amount__c}"/>
				<apex:column headerValue="Type">
					<apex:selectList styleClass="type_opp" value="{!typeOfOpp}"  size="1">
						<apex:selectOptions value="{!fastType}" />
					</apex:selectList>
				</apex:column>

				<apex:column headerValue="TYpe" value="{!f.Type__c}">
				</apex:column>

				<apex:column headerValue="Pessimistic">
				<apex:inputText styleClass="pessimist" value="{!f.Opp_Amount__c}"/>
				</apex:column>

				<apex:column headerValue="Forecast Exit">
				<apex:inputText styleClass="forecast_exit" value="{!f.Opp_Amount__c}"/>
				</apex:column>

				<apex:column headerValue="Optimistic">
				<apex:inputText styleClass="optimist" value="{!f.Opp_Amount__c}"/>
				</apex:column>
				<apex:column headerValue="Is closed ?">
				<apex:outputText value="{!f.IsClosed__c}"/>
				</apex:column>
	</apex:pageBlockTable>
</apex:pageBlock>

 
Glyn Anderson 3Glyn Anderson 3
Jeremy,  Try changing line 06 of the VF code above to the line below.  This will set the field on the FAST_OPP__c record directly, without using a separate property.  Each record will maintain its own value.  Then also delete lines 01 and 16 of the Apex code in your original post.  Let me know if that acheives the desired result.

<pre>
    <apex:selectList styleClass="type_opp" value="{!f.Type__c}" size="1">
</pre>
 
Jeremy DeseezJeremy Deseez
Hello,
I've made the change, and now nothing happen when I save the table.
The Lists which come from my Controller are now empty.

Thanks for your help, I will check that
 
Jeremy DeseezJeremy Deseez
Hi, 
I've made a mistake, It's working now, thanks a lot :)
Glyn Anderson 3Glyn Anderson 3
Glad to hear that it's working!  Could you please mark this question as "Solved"?  Thank you!