Skip to content

Instantly share code, notes, and snippets.

@tyoshikawa1106
Created April 28, 2013 04:29
Show Gist options
  • Save tyoshikawa1106/5475882 to your computer and use it in GitHub Desktop.
Save tyoshikawa1106/5475882 to your computer and use it in GitHub Desktop.
-- 参考サイト -- Checking The Boxes, Getting The Input: http://www.laceysnr.com/2013/04/checking-boxes-geting-input.html
public with sharing class CheckingTheBoxesController {
public Map<Id, Boolean> selected {get; set;}
public List<Opportunity> opportunities {get; set;}
public Boolean forAll {get; set;}
public CheckingTheBoxesController() {
this.selected = new Map<Id, Boolean>();
this.opportunities = new List<Opportunity>();
for(Opportunity o : [select Id, Name from Opportunity])
{
this.selected.Put(o.Id, false);
this.opportunities.Add(o);
}
}
public void ToggleAll()
{
for(Id oppty : this.selected.keyset())
{
this.selected.Put(oppty, this.forAll);
}
}
}
<apex:page controller="CheckingTheBoxesController" tabStyle="Opportunity" id="page">
<apex:form>
<apex:pageBlock>
<apex:pageBlockTable value="{!opportunities}" var="o" id="list">
<apex:column style="width:30px">
<apex:facet name="header">
<apex:inputCheckbox value="{!forAll}">
<apex:actionSupport event="onchange" action="{!ToggleAll}" rerender="list"/>
</apex:inputCheckbox>
</apex:facet>
<apex:inputCheckbox value="{!selected[o.Id]}"/>
</apex:column>
<apex:column>
<apex:outputField value="{!o.Name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment