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
ptepptep 

Setting Apex Map values from a Visualforce page

I posted something similar to this the other day and thought it answered my question, but it doesn't.

 

Is it possible to store values in a Map by calling the map in a formula? For example:

 

	<table>
	
	<apex:repeat value="{!myOpts}" var="f">
		<tr>
			<td class="fieldLabel">{!myOpts[f]}</td>
			<td>
				<apex:selectList value="{!myVals[f]}" size="1">
					<apex:selectOptions value="{!selectOpts}"/>
				</apex:selectList>
			</td>
		</tr>
	
	</apex:repeat>
	</table>
	

Assuming the Maps myOpts and myVals have the same keys, what I want to do is store the selected value in the entry for myVals[f]. Displaying the value myOpts[f] as a label works fine. But setting the myVals[f] entry as the selectList value does not work.

 

Is this possible using a different syntax, e.g. writing some kind of wrapper function?  (I don't think it is)

 

thanks

tukmoltukmol

you're almost there.

 

what you can do is to have additional String list variabe/property in your controller which will serve as the common key for myOpts and myVals.

 

i.e.

in controller...

public List<String> keys {
	get {return new List<String>(myOpts.keyset());}
}

 

you would then use 'keys' as the iterator... i.e.

 

<apex:repeat value="{! keys}" var="index">

 

then use it as:

 

{! myOpts[index]}

{! myVals[index]}

 

however, as mentioned in the documentation about Map in FV, you can get value from it. the page won't post back the value to the controller.

ptepptep

Thank you for your response, but this does not answer my question - in fact it gives the answer to the question I mentioned having already asked and which was already answered. I know you can get map values, my question is about "Setting Apex Map values". Which it seems like you also think I can't do.

tukmoltukmol

ok. perhaps i misunterstood.

 

i thought you were trying to set the value for your 'SelectList'

 

in that case, the documentation was enough to answer your query.

ptepptep

Where is this covered in the documentation?

tukmoltukmol

ptep wrote:

Where is this covered in the documentation?


in the answer to the link you posted above.