I am having a peculiar predicament in regards to using apex:actionSupport.
I am selecting a collection of values on a VisualForce page (through the use of a wrapper class in the controller) with the use of an inputCheckbox tag on the page.
The only problem is, the onclick event that the actionSupport tag is linked to, only fires after one of my output panels rerenders the list. Otherwise, it does not work.
Here is my code:
In Visualforce
<apex:commandButton action="{!Add_To_Friendship_List}" reRender="List" value="Add New Friend to List!"/>
<apex:outputPanel id="List">
<apex:outputPanel id="Listable">
<apex:dataTable value="{!Entries}" var="Friend">
<apex:column >
{!Friend.Display_Name}
<apex:inputCheckbox value="{!Friend.Is_Chosen}" selected="{!Friend.Is_Chosen}">
<apex:actionSupport event="onclick" action="{!Recount}" reRender="CounterPanel"/>
</apex:inputCheckbox>
</apex:column>
</apex:dataTable>
</apex:outputPanel>
</apex:outputPanel>
......
<apex:outputPanel id="CounterPanel">
<apex:outputPanel >
{!Current_Friend_Count}
</apex:outputPanel>
</apex:outputPanel>
Things I have also tried
I have also tried using an actionFunction tag and linking the checkboxes onclick event to that (as well as on select) but it still wont fire until the "List" output panel is updated.
I have also removed the selected attribute in the inputCheckbox tag to no avail as well.
Any suggestion on why that is and how to get it to work properly the first time is most appreciated.
Added Content
*In Apex - Friendship_Wizard controller*
private Integer Selection_Count;
private List<Possible_Friend_Wrap> Current_Friends;
public List<Possible_Friend_Wrap> Current { get { return this.Current_Friends; } }
private List<Possible_Friend_Wrap> New_Friendship_Entries;
public List<Possible_Friend_Wrap> Entries { get { return this.New_Friendship_Entries; } }
public class Possible_Friend_Wrap
{
public Friend__c One_Friend { get; private set; }
public String Display_Name { get; private set; }
public Boolean Is_Chosen { get; set; }
protected Boolean In_DB { get; set; }
public Possible_Friend_Wrap(Friend__c Friend, Boolean Is_Created)
{
this.One_Friend = Friend;
this.In_DB = Is_Created;
this.Display_Name = this.One_Friend.First_Name__c;
if(this.One_Friend.Middle_Name__c != null)
this.Display_Name += ' ' + this.One_Friend.Middle_Name__c;
this.Display_Name += ' ' + this.One_Friend.Last_Name__c;
this.Is_Chosen = false;
}
}
public PageReference Edit_Friendship()
{
this.New_Friendship_Entries = new List<Possible_Friend_Wrap>();
this.Current_Friends = new List<Possible_Friend_Wrap>();
this.Friend_Addtion = new Friend__c();
this.Selection_Count = 0;
for(Friend__c Found_Friend : [SELECT Middle_Name__c, Last_Name__c, Id, First_Name__c FROM Friend__c])
this.Current_Friends.add(new Possible_Friend_Wrap(Found_Friend, true));
PageReference Friendship_Editor = Page.FriendsPage;
return Friendship_Editor;
}
public PageReference Add_To_Friendship_List()
{
if(this.New_Friendship_Entries == null)
this.New_Friendship_Entries = new List<Possible_Friend_Wrap>();
this.New_Friendship_Entries.add(new Possible_Friend_Wrap
(this.Friend_Addtion.clone(true, true), false));
this.Friend_Addtion = new Friend__c();
return null;
}
public Integer Current_Friend_Count
{
get { return this.Selection_Count; }
}
public PageReference Recount()
{
this.Selection_Count = 0;
if(this.New_Friendship_Entries != null)
{
for(Possible_Friend_Wrap New_Wrap : this.New_Friendship_Entries)
if(New_Wrap.Is_Chosen == true)
this.Selection_Count++;
}
this.Checker = 'Counted new entries selected.';
if(this.Current_Friends != null)
{
for(Possible_Friend_Wrap Old_Wrap : this.Current_Friends)
if(Old_Wrap.Is_Chosen == true)
this.Selection_Count++;
}
return null;
}