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;
}
}
{ get; set; }
helped.