How would I go about passing the ID from a record in an apex:repeat iteration into a variable used in a controller method and then display the value the method returns in the VF page?

I've hacked around quite a bit with apex:param but haven't been able to get this to work as expected.

Here's where I'm at so far:

<apex:repeat value="{!mycourses}" var="course">
  <div class="course clearfix">
    <div class="progress-container">
      <apex:input type="text" value="{!wholeNumberComplete}" styleclass="progress">
        <apex:param name="courseId" value="{!course.id}" assignTo="{!courseId}"/>

public List<Training_Plan__c> mycourses;
public List<Learning_Assignment__c> learnings;
public Decimal displayNumber {get; set;}

public List<almond__Training_Plan__c> getmycourses() {
  mycourses = SystemUtils.getCourses();
  learnings = SystemUtils.getLearningAssignments(courseId);
  displayNumber = learnings.size();
  return mycourses;

Thanks in advance for the assistance.

2 Answers 2


I'm not sure if you didn't copy all of your code over or not but I do not see a variable named courseId. Also from the developer guide...

The component can only be a child of the following components:


There is an awesome blog that will walk you through an example as well here. Example from the blog:

<apex:commandButton value="Del" action="{!delCont}" rerender="all">
   <apex:param name="contIdParam" value="{!cont.id}" assignTo="{!contIdChosen}"/>

public String contIdChosen {get; set;}


You can always use Maps for this Using Maps in Visualforce

Check below examples

public Map<String,String> directors {
get {
    return new Map<String, String> {
        'Kieslowski' => 'Poland', 
        'del Toro' => 'Mexico', 
        'Gondry' => 'France'

Using Visualforce for same

<apex:repeat value="{!directors}" var="dirKey">
    <apex:outputText value="{!dirKey}" /> -- 
    <apex:outputText value="{!directors[dirKey]}" /><br/>

In your case you want to process logic inside repeat ,which i will avoid and instead already cache the logic for all keys inside map.

Check below example as well

<apex:page controller="ListsMapsController">
<apex:outputPanel id="box" layout="block">
    <apex:form >

        <apex:repeat value="{!inputFields}" var="fieldKey">
            <apex:outputText value="{!fieldKey}"/>: 
            <apex:inputText value="{!inputFields[fieldKey]}"/><br/>

        <apex:commandButton action="{!submitFieldData}" 
            value="Submit" id="button" rerender="box"/>


public class ListsMapsController {

public Map<String, String> inputFields { get; set; }

public ListsMapsController() {
    inputFields = new Map<String, String> { 
        'firstName' => 'Jonny', 'lastName' => 'Appleseed', 'age' => '42' };

public PageReference submitFieldData() {
    return null;

public void doSomethingInterestingWithInput() {
    inputFields.put('age', (Integer.valueOf(inputFields.get('age')) + 10).format());
  • Thanks for the reply but I'm still stuck...I'm iterating over a list of sObjects records and need to take the ID from each record and pass it into a variable used in a controller method. The controller method uses this record ID to create a list of child records. From this list of child records, I'm then performing a math calculation and am returning a decimal. This decimal is then what needs to be displayed in the VF page.
    – John_Henry
    Sep 17, 2015 at 19:14
  • you would need an action to do this .Provide a button and run action for all this .Doing everything inside repeat is not recommended . Sep 17, 2015 at 19:20
  • Is there a way I could invoke the action on page load?
    – John_Henry
    Sep 17, 2015 at 19:25
  • Use Action attribute sir .apex:page has action to call all your actions Sep 17, 2015 at 19:27
  • Thanks. How would I go about passing the ID from each record in apex:repeat into the method called from the action attribute?
    – John_Henry
    Sep 17, 2015 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.