You need to sign in to do that
Don't have an account?

how to use checkboxes with apex:selectList
Hi Guys,
I want to display a table of Account records with checkboxes in such a way that, whenever a checkbox is selected,it should display the related
Opportunities for the specific Account. Only one Account record must be selected at a time.
I was able to achieve similar functionality through Picklist, but how to do the same with checkboxes.
My Code for picklist is shown below
Controller
--------------
public class WrapperOpp {
public List<OppWrapper> Opplist = new List<OppWrapper>();
public String SelectedValue {get;set;}
public List<SelectOption> Accs {get{
List<SelectOption> AccName = new List<SelectOption>();
for(Account a :[Select Id, name from Account limit 10])
{
AccName.add(new SelectOption(a.name,a.name));
}
return AccName;
}
}
public PageReference refresh()
{
Opplist .clear();
for(Account a :[Select id,name,(Select name from opportunities) from Account where name =:SelectedValue])
{
for (opportunity opp :a.opportunities)
Opplist.add(new OppWrapper(false,opp));
}
return null;
}
public List<OppWrapper> getOppList()
{
System.debug('count'+Opplist.size());
return Opplist;}
public class OppWrapper{
public Boolean selected{get;set;}
public Opportunity opp{get;set;}
public OppWrapper(Boolean selected1, Opportunity opp1)
{
selected = selected1;
opp = opp1;
}
}
}
VF page
-------------
<apex:page controller="WrapperOpp" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:selectList value="{!SelectedValue}" size="1">
<apex:selectOptions value="{!Accs}"/>
<apex:actionSupport event="onchange" action="{!refresh}" reRender="OppTable"/>
</apex:selectList>
<apex:pageBlockTable value="{!Opplist}" id="OppTable" var="o">
<apex:column value="{!o.opp.Name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks,
Abhilash
I want to display a table of Account records with checkboxes in such a way that, whenever a checkbox is selected,it should display the related
Opportunities for the specific Account. Only one Account record must be selected at a time.
I was able to achieve similar functionality through Picklist, but how to do the same with checkboxes.
My Code for picklist is shown below
Controller
--------------
public class WrapperOpp {
public List<OppWrapper> Opplist = new List<OppWrapper>();
public String SelectedValue {get;set;}
public List<SelectOption> Accs {get{
List<SelectOption> AccName = new List<SelectOption>();
for(Account a :[Select Id, name from Account limit 10])
{
AccName.add(new SelectOption(a.name,a.name));
}
return AccName;
}
}
public PageReference refresh()
{
Opplist .clear();
for(Account a :[Select id,name,(Select name from opportunities) from Account where name =:SelectedValue])
{
for (opportunity opp :a.opportunities)
Opplist.add(new OppWrapper(false,opp));
}
return null;
}
public List<OppWrapper> getOppList()
{
System.debug('count'+Opplist.size());
return Opplist;}
public class OppWrapper{
public Boolean selected{get;set;}
public Opportunity opp{get;set;}
public OppWrapper(Boolean selected1, Opportunity opp1)
{
selected = selected1;
opp = opp1;
}
}
}
VF page
-------------
<apex:page controller="WrapperOpp" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:selectList value="{!SelectedValue}" size="1">
<apex:selectOptions value="{!Accs}"/>
<apex:actionSupport event="onchange" action="{!refresh}" reRender="OppTable"/>
</apex:selectList>
<apex:pageBlockTable value="{!Opplist}" id="OppTable" var="o">
<apex:column value="{!o.opp.Name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks,
Abhilash
Try this code