Objective of my VF :
Render any random 10 contacts in the upper part of VF page.
Depending upon my interaction with input checkbox, the contacts available in the list (lower part) should get updated.
This is my VF Code :
<apex:page controller="SelectContactsController">
<apex:form >
<apex:pagemessages />
<apex:pageblock title="Contacts">
<apex:pageblockbuttons >
<apex:commandbutton action="{!save}" value="Save" />
<apex:commandbutton action="{!cancel}" value="Cancel" />
</apex:pageblockbuttons>
<apex:pageblocksection >
<apex:repeat value="{!con_wrap_list}" var="cw">
<apex:pageblocksectionitem >
<apex:inputCheckbox value="{!cw.isselected}">
**<apex:actionsupport action="{!draw_list}" event="onchange"/>** //HERE
</apex:inputcheckbox>
<apex:outputfield value="{!cw.con_input.Name}"/>
</apex:pageblocksectionitem>
</apex:repeat>
</apex:pageblocksection>
<hr />
<apex:pageblocksection >
<apex:pageblocksectionitem id="pgbsi">
<apex:outputLabel >List</apex:outputLabel>
<apex:selectList multiselect="false" size="1">
<apex:selectoptions value="{!con_select_list}">
</apex:selectoptions>
</apex:selectList>
</apex:pageblocksectionitem>
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
This is my controller code :
public with sharing class SelectContactsController {
public PageReference save() {return null;}
public PageReference cancel() {return null;}
public List<ContactWrapper> con_wrap_list{get;set;}
public List<SelectOption> con_select_list{get;set;}
public class ContactWrapper
{
public Contact con_input {get;set;}
public Boolean isselected{get;set;}
public ContactWrapper(Contact c_inp)
{
con_input = c_inp;
isselected = true;
}
}
public PageReference draw_list()
{
con_select_list = new List<SelectOption>();
for(ContactWrapper c1 : con_wrap_list)
{
if(c1.isselected)
{
con_select_list.add(new SelectOption(c1.con_input.name,c1.con_input.name));
}
}
return null;
}
public SelectContactsController()
{
con_wrap_list = new List<ContactWrapper>();
for(Contact c : [SELECT ID,Name FROM Contact LIMIT 10])
{
con_wrap_list.add(new ContactWrapper(c));
}
draw_list();
}
}
Issue :
My understanding is that if I use "rerender=" in apex:actionsupport then after the AJAX is done the UI element mentioned in the rerender attribute will be rerendered.
But what happens is that if I keep rerender="pgbsi" the select list is not getting updated at all.
Only when I remove the rerender attribute completely from the action function then the list is getting redrawn after updating input checkboxes.
Can someone tell me why ?.
Also can someone tell me the purpose of value attribute in apex:selectlist. I went through the docs and still unclear as to what role that attribute plays. For example in this example I am able to achieve my purpose of redrawing without using this "value" attribute in apex:selectlist at all.
So what exactly is the use of this attribute ?