Skip to content

Instantly share code, notes, and snippets.

@reuf
Forked from martyychang/ActionSupportParamDemo.page
Created December 20, 2015 23:09
Show Gist options
  • Save reuf/256c097301e92fe39cf5 to your computer and use it in GitHub Desktop.
Save reuf/256c097301e92fe39cf5 to your computer and use it in GitHub Desktop.
Demonstration of how apex:actionSupport and apex:param are supposed to work together
<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>
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment