2

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.

enter image description here

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 ?

2
  • The error could be bcoz of the PageReference added in the draw_list method. Can you make the return type of the method as void and check once. Commented Apr 30, 2015 at 10:20
  • @RitikaBhrgv Hi i tried changing the return type to void but still the issue remains...i tried putting the list within apex:outputpanel also but no luck...the only way I am able to refresh the list is by removing the rerender attribute completely from actionsupport component. Commented Apr 30, 2015 at 12:20

1 Answer 1

0

When you not specify this parameter whole page is render. The source of issue you are facing is wrong element Id. Please open page in broswer and check actual picklist Id.

Please check: https://www.salesforce.com/docs/developer/pages/Content/pages_variables_global_component.htm

It may be helpful :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .