[SalesForce] apex:param not assigning value within apex:actionSupport for apex:inputCheckbox

I have a simple proof of concept that is not working as expected, and what appears to be happening is that the apex:param is not actually assigning the specified value to the controller property as defined when adding the component to the page. How can I get the assignTo attribute to work properly?

Below is the simple Visualforce page used for the proof of concept. To get it to work, you'll need to create an IsActive__c checkbox field on the Account object. The idea is that when a user clicks a checkbox, the selected Account ID is displayed at the bottom of the page. But what's happening is that the selected value is not being passed to the controller.

<apex:page controller="ActionSupportParamDemoController">
    <apex:form>
        <apex:repeat value="{!accounts}" var="account">
            <apex:inputCheckbox value="{!account.IsActive__c}">
                <apex:actionSupport event="onchange"
                                    action="{!handleAccountCheckboxChange}">
                    <apex:param id="account" name="accountId" value="{!account.Id}"
                                assignTo="{!targetAccountId}"/>
                </apex:actionSupport>
            </apex:inputCheckbox>
            {!account.Name}
        </apex:repeat>
    </apex:form>
    Selected: {!selectedAccountId}
</apex:page>

Below is the controller supporting the Visualforce page.

public class ActionSupportParamDemoController {
    private Id targetAccountId;
    public Id selectedAccountId { get; set; }

    public List<Account> getAccounts() {
        return [
            SELECT Id, Name, Website, IsActive__c
            FROM Account
        ];
    }

    public Id getTargetAccountId() {
        return targetAccountId;
    }

    public PageReference handleAccountCheckboxChange() {
        System.debug('targetAccountId: ' + targetAccountId);
        selectedAccountId = targetAccountId;
        return null;
    }

    public void setTargetAccountId(Id value) {
        targetAccountId = value;
    }
}

Best Answer

The actionSupport tag is to enable AJAX support on the page and hence only works for AJAX requests. In order to get it working, all you need to do is put the "Selected:" portion in an outputPanel and add reRender to the actionSupport tag. See example code below that works:

<apex:page controller="ActionSupportParamDemoController">
<apex:form >
    <apex:repeat value="{!accounts}" var="account">
        <apex:inputCheckbox value="{!account.IsActive__c}">
            <apex:actionSupport event="onchange"
                                action="{!handleAccountCheckboxChange}"
                                reRender="ResultPanel">
                <apex:param id="account" name="accountId" value="{!account.Id}"
                            assignTo="{!targetAccountId}"/>
            </apex:actionSupport>
        </apex:inputCheckbox>
        {!account.Name}
    </apex:repeat>
</apex:form>
<apex:outputPanel id="ResultPanel">
    Selected: {!selectedAccountId}
</apex:outputPanel>

No change is required on the controller.