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


Unknown property 'n'


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

Visualforce page

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

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

Desired Layou

1 Answer 1


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


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>();


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

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 .