You need to sign in to do that
Don't have an account?
<apex:inputCheckbox> issue after assigning value.
Hi,
I'm facing a bit weird problem here, Below is the business logic which populates the accounts in dropdownlist and on change, it populates the contacts from respective account in datatable. I want to get contact ids which have been selected using inputcheckbox.
The issue I am facing is, when I assign value to <apex:inputcheckbox>, it does not shows next result when I changes the value in dropdownlist.
Please, let me know what I'm missing here
CLASS
---------------------------------------
public class PopulateAccContact{
public String strMessage { get; set; }
public id aid {get;set;}
public boolean render {get;set;}
List<selectoption> options=new List<selectoption>();
public List<Contact> lstcont{get;set;}
public lonchangeaccount(){
lstcont=new List<contact>();
}
Map<id,List<contact>> maplstcont=new Map<id,List<contact>>();
public List<SelectOption> getValues(){
options.clear();
options.add(new selectOption('--None--','-- Select Account --'));
for(Account acc:[select id,name,(select id,name,email from contacts)from account]){
options.add(new selectOption(acc.id,acc.name));
maplstcont.put(acc.id,acc.contacts);
}
return options;
}
public void Contactlst(){
lstcont.clear();
strMessage = ' : '+ aid;
if(aid!=null){
render=true;
lstcont.addAll(maplstcont.get(aid));
}
}
}
APEX
---------------------------------------
<apex:page controller="PopulateAccContact">
<apex:form >
<apex:pageBlock >
<apex:actionFunction action="{!Contactlst}" name="change"/>
<apex:selectList value="{!aid}" multiselect="false" size="1" onchange="change();" >
<apex:selectOptions value="{!values}"/>
</apex:selectList>
<apex:outputLabel id="lblShowStatus" value="{!strMessage}"></apex:outputLabel>
<apex:outputPanel id="pbt1">
<apex:pageBlockTable value="{!lstcont}" var="c">
<apex:column >
<apex:inputCheckbox value="{!c.id}" id="icbCID" />
</apex:column>
<apex:column value="{!c.id}"/>
<apex:column value="{!c.name}"/>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks in advance.
Hi,
Try the below code snippet:
--- vf page------
<apex:page controller="PopulateAccContact1">
<script>
function callactionfun(picklistval)
{
change(picklistval);
}
</script>
<apex:form >
<apex:pageBlock >
<apex:actionFunction action="{!Contactlst}" reRender="condisplay" name="change">
<apex:param value="" assignTo="{!aid}" name="assignvalue"/>
</apex:actionFunction>
<apex:selectList value="{!aid}" multiselect="false" size="1" onchange="callactionfun(this.value);" >
<apex:selectOptions value="{!values}"/>
</apex:selectList>
<apex:outputPanel id="condisplay">
<apex:outputLabel id="lblShowStatus" value="{!strMessage}"></apex:outputLabel>
<apex:outputPanel id="pbt1">
<apex:repeat value="{!maplstcont}" var="getmap" >
<apex:pageBlockTable value="{!maplstcont[aid]}" var="c" rendered="{!IF(getmap==aid,true,false)}">
<apex:column >
<apex:inputCheckbox value="{!c.id}" id="icbCID" />
</apex:column>
<apex:column value="{!c.id}"/>
<apex:column value="{!c.name}"/>
</apex:pageBlockTable>
</apex:repeat>
</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
------- apex controller------
public class PopulateAccContact1{
public String strMessage { get; set; }
public id aid {get;set;}
public boolean render {get;set;}
public Map<id,List<contact>> maplstcont{get;set;}
List<selectoption> options=new List<selectoption>();
public List<Contact> lstcont{get;set;}
public PopulateAccContact1(){
lstcont=new List<contact>();
maplstcont=new Map<id,List<contact>>();
//aid ='';
}
public List<SelectOption> getValues(){
options.clear();
options.add(new selectOption('--None--','-- Select Account --'));
for(Account acc:[select id,name,(select id,name,email from contacts)from account]){
options.add(new selectOption(acc.id,acc.name));
maplstcont.put(acc.id,acc.contacts);
}
return options;
}
public void Contactlst(){
lstcont.clear();
strMessage = ' : '+ aid;
if(aid!=null){
render=true;
lstcont.addAll(maplstcont.get(aid));
}
}
}
All Answers
Hi,
Try the below code snippet as reference:
--------------- Vf page---------------
<apex:page controller="PopulateAccContact" >
<apex:form >
<apex:selectList size="1" value="{!aid}">
<apex:selectOptions value="{!Values}"></apex:selectOptions>
<apex:actionSupport event="onchange" action="{!Contactlst}" reRender="displayblock" />
</apex:selectList>
<apex:outputPanel id="displayblock">
<apex:outputLabel id="lblShowStatus" value="{!strMessage}"></apex:outputLabel>
<apex:pageBlock >
<apex:pageBlockTable value="{!lstcont}" var="c">
<apex:column value="{!c.id}" />
<apex:column value="{!c.name}" />
<apex:column value="{!c.email}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>
----------------- Apex Controller --------------------------
public class PopulateAccContact{
public String strMessage { get; set; }
public id aid {get;set;}
public boolean render {get;set;}
List<selectoption> options=new List<selectoption>();
public List<Contact> lstcont{get;set;}
public PopulateAccContact(){
lstcont=new List<contact>();
}
public List<SelectOption> getValues(){
options.clear();
options.add(new selectOption('--None--','-- Select Account --'));
for(Account acc:[select id,name from account]){
options.add(new selectOption(acc.id,acc.name));
}
return options;
}
public void Contactlst()
{
lstcont.clear();
if(aid!=null)
{
strMessage = ' : '+ aid;
render=true;
lstcont=[select id,name,email from contact where accountid=:aid];
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi Ankit,
Thanks for your reply.
It still not working for me when I add <apex:inputCheckbox value="{!c.id}" id="cbContact" /> in <apex:pageBlockTable>. It does not pull contacts when I change account in dropdownlist for second time.
What I want is; to get all checked contacts populated when I select respective account. Let me know, what needs to be done.
Hi,
Try the below code snippet:
--- vf page------
<apex:page controller="PopulateAccContact1">
<script>
function callactionfun(picklistval)
{
change(picklistval);
}
</script>
<apex:form >
<apex:pageBlock >
<apex:actionFunction action="{!Contactlst}" reRender="condisplay" name="change">
<apex:param value="" assignTo="{!aid}" name="assignvalue"/>
</apex:actionFunction>
<apex:selectList value="{!aid}" multiselect="false" size="1" onchange="callactionfun(this.value);" >
<apex:selectOptions value="{!values}"/>
</apex:selectList>
<apex:outputPanel id="condisplay">
<apex:outputLabel id="lblShowStatus" value="{!strMessage}"></apex:outputLabel>
<apex:outputPanel id="pbt1">
<apex:repeat value="{!maplstcont}" var="getmap" >
<apex:pageBlockTable value="{!maplstcont[aid]}" var="c" rendered="{!IF(getmap==aid,true,false)}">
<apex:column >
<apex:inputCheckbox value="{!c.id}" id="icbCID" />
</apex:column>
<apex:column value="{!c.id}"/>
<apex:column value="{!c.name}"/>
</apex:pageBlockTable>
</apex:repeat>
</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
------- apex controller------
public class PopulateAccContact1{
public String strMessage { get; set; }
public id aid {get;set;}
public boolean render {get;set;}
public Map<id,List<contact>> maplstcont{get;set;}
List<selectoption> options=new List<selectoption>();
public List<Contact> lstcont{get;set;}
public PopulateAccContact1(){
lstcont=new List<contact>();
maplstcont=new Map<id,List<contact>>();
//aid ='';
}
public List<SelectOption> getValues(){
options.clear();
options.add(new selectOption('--None--','-- Select Account --'));
for(Account acc:[select id,name,(select id,name,email from contacts)from account]){
options.add(new selectOption(acc.id,acc.name));
maplstcont.put(acc.id,acc.contacts);
}
return options;
}
public void Contactlst(){
lstcont.clear();
strMessage = ' : '+ aid;
if(aid!=null){
render=true;
lstcont.addAll(maplstcont.get(aid));
}
}
}
Thanks Ankit!!