[SalesForce] Select a row using checkbox wrapper class

I have a pageblock with 2 columns and a checkbox column in Apex:repeat. Im trying to select the whole by selecting the checkbox. when I select the checkbox, the value is not being captured. Yes im using the wrapper class as per the salesforce example.

In my class, the list "selectedEngs" is empty. To this list, Im adding the selected rows. But the size is zero, even after checkbox is ticked.

Did I miss anything, below is my code. Please let me know.

Here is the vf PAGE. 1 text field and checkbox.

<apex:repeat value="{!Engagements}" var="item"> 
    <apex:pageBlockSection id="Selected_PBS" columns="3" >
        <apex:outputPanel layout="block">
            <label>Program</label>
            <apex:outputText value="{!item.eng.Program__c}"/>
        </apex:outputPanel>

        <apex:outputPanel layout="block">                              
            <apex:inputCheckbox value="{!item.selected}" id="checkedone">
                <apex:actionSupport event="onClick" action="{!applySelectedFlags}"/>                                             
            </apex:inputCheckbox>
        </apex:outputPanel>
    </apex:pageBlockSection>
</apex:repeat>

Apex class is below

List <Engagement__c> selectedEngs = new list<Engagement__c>();
List<EngagementWrapper> engList = new List<EngagementWrapper>();

public PageReference applySelectedFlags()
{
    //selectedEngs.clear();
    for(EngagementWrapper engwrapper : engList)
    {
        if(engwrapper.selected == true)
            selectedEngs.add(engwrapper.eng);
    }
    return null;
}

public List<EngagementWrapper> getEngagements()
{    
    engList.clear();
    for(Engagement__c e : studentList)
        engList.add(new EngagementWrapper(e));

    return engList;
}

public List<Engagement__c> GetSelectedEngs()
{
    if(selectedEngs.size()>0)
        return selectedEngs;
    else
        return null;
}

help!

cheers!

Best Answer

By setting rendered=false on the apex:actionSupport you are effectively turning that feature off. Remove that and the getSelected method will be invoked when a checkbox is clicked.

By the way, the get method prefix is one way of exposing properties to the Visualforce page, but action methods can be called whatever you like. So getSelected might be better called something like applySelectedFlags - clear naming generally makes code easier to follow.