0

How can I loop the repeat and display the apex:inputCheckbox?

Error

Unknown property 'n'

Controller

public List<String> ListOfNames {
    get {
        List<String> nameList = new List<String>(); 
        for(String s : /*SOQL*/) { 
            nameList.add(s.Name);
        }
        return nameList;
    }
}

Visualforce page

<apex:repeat value="{!ListOfNames}" var="n">    
    <apex:inputCheckbox value="{!n}"/> 
</apex:repeat>

Here is what I want the output to be look like:

Desired Layou

1 Answer 1

5

You just need to use the apex:selectCheckboxes tag. Below is a simple demo:

Controller

public with sharing class Throwaway
{
    public List<SelectOption> options { get; private set; }
    public List<SelectOption> selections { get; set; }

    public Throwaway()
    {
        options = new List<SelectOption>
        {
            new SelectOption('1', 'One'),
            new SelectOption('2', 'Two'),
            new SelectOption('3', 'Three'),
            new SelectOption('4', 'Four'),
            new SelectOption('5', 'Five')
        };
        selections = new List<SelectOption>();
    }
}

Page

<apex:page controller="Throwaway">
    <apex:form >
        <apex:selectCheckboxes value="{!selections}" layout="pageDirection">
            <apex:selectOptions value="{!options}" />
        </apex:selectCheckboxes>
    </apex:form>
</apex:page>

Note the layout attribute. It defaults to lineDirection (horizontal), which is not what you want. Hence the change to pageDirection, which makes it vertical.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .