You need to sign in to do that
Don't have an account?
RohitJ
Populating apex:pageBlockTable from Apex
Hi All,
I am very new to this. I have two selectList on my VF page, when i select the event selectList i am passing it to Apex class, in the apex class i am running another SOQL query to fetch sessions on basis of Event value passed. I am unable to populate the table.
VF code :
<apex:page controller="AgendaBuilderController">
<apex:form >
<apex:pageBlock title="Agenda Builder">
<apex:outputLabel value="Select Attendee">
<apex:selectList multiselect="false" size="1">
<apex:selectOptions value="{!leadNames}">
</apex:selectOptions>
</apex:selectList>
</apex:outputLabel>
<apex:outputLabel value="Select Event">
<apex:selectList multiselect="false" size="1" value="{!selectedEvent}">
<apex:selectOptions value="{!campgnNames}">
</apex:selectOptions>
<apex:commandButton value="Go" action="{!showSessions}" reRender="abcd">
</apex:commandButton>
</apex:selectList>
</apex:outputLabel>
<apex:outputLabel value="{!selectedEvent}" id="abcd"></apex:outputLabel>
<apex:pageBlockTable value="{!displaySessions}" var="a" title="Session Details">
<apex:column value="{!a.Name}">
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code :
public class AgendaBuilderController {
public String attendee { get;set;}
public String event { get;set;}
public String selectedEvent { get;set;}
public String session { get;set;}
List<Campaign> eventId = new List<Campaign>();
List<Session__c> sessionList = new List<Session__c>();
public List<Session__c> displaySessions { get; set;}
List<Campaign> campgn = [SELECT Name from Campaign];
public List<Campaign> getCampgn(){
return campgn;
}
List<selectOption> options = new List<selectOption>();
public List<selectOption> getLeadNames() {
for(Lead leads : [select name from Lead]) {
options.add(new selectOption(leads.name,leads.name));
}
return options;
}
List<selectOption> camgnOptions = new List<selectOption>();
public List<selectOption> getCampgnNames() {
for(Campaign campaigns : [SELECT name from Campaign]) {
camgnOptions.add(new selectOption(campaigns.name,campaigns.name));
}
return camgnOptions;
}
public void showSessions(){
System.debug('Selected Event '+selectedEvent);
eventId = [SELECT Id from Campaign WHERE Name=:selectedEvent];
System.debug('Campaign Id ' +eventId);
displaySessions = [SELECT Name from Session__c where event__c =:eventId];
}
}
I am pretty sure i am going wrong in the code. Please help in this.
Regards,
Rohit
I am very new to this. I have two selectList on my VF page, when i select the event selectList i am passing it to Apex class, in the apex class i am running another SOQL query to fetch sessions on basis of Event value passed. I am unable to populate the table.
VF code :
<apex:page controller="AgendaBuilderController">
<apex:form >
<apex:pageBlock title="Agenda Builder">
<apex:outputLabel value="Select Attendee">
<apex:selectList multiselect="false" size="1">
<apex:selectOptions value="{!leadNames}">
</apex:selectOptions>
</apex:selectList>
</apex:outputLabel>
<apex:outputLabel value="Select Event">
<apex:selectList multiselect="false" size="1" value="{!selectedEvent}">
<apex:selectOptions value="{!campgnNames}">
</apex:selectOptions>
<apex:commandButton value="Go" action="{!showSessions}" reRender="abcd">
</apex:commandButton>
</apex:selectList>
</apex:outputLabel>
<apex:outputLabel value="{!selectedEvent}" id="abcd"></apex:outputLabel>
<apex:pageBlockTable value="{!displaySessions}" var="a" title="Session Details">
<apex:column value="{!a.Name}">
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code :
public class AgendaBuilderController {
public String attendee { get;set;}
public String event { get;set;}
public String selectedEvent { get;set;}
public String session { get;set;}
List<Campaign> eventId = new List<Campaign>();
List<Session__c> sessionList = new List<Session__c>();
public List<Session__c> displaySessions { get; set;}
List<Campaign> campgn = [SELECT Name from Campaign];
public List<Campaign> getCampgn(){
return campgn;
}
List<selectOption> options = new List<selectOption>();
public List<selectOption> getLeadNames() {
for(Lead leads : [select name from Lead]) {
options.add(new selectOption(leads.name,leads.name));
}
return options;
}
List<selectOption> camgnOptions = new List<selectOption>();
public List<selectOption> getCampgnNames() {
for(Campaign campaigns : [SELECT name from Campaign]) {
camgnOptions.add(new selectOption(campaigns.name,campaigns.name));
}
return camgnOptions;
}
public void showSessions(){
System.debug('Selected Event '+selectedEvent);
eventId = [SELECT Id from Campaign WHERE Name=:selectedEvent];
System.debug('Campaign Id ' +eventId);
displaySessions = [SELECT Name from Session__c where event__c =:eventId];
}
}
I am pretty sure i am going wrong in the code. Please help in this.
Regards,
Rohit
Yor ReRendering the OutPut Label not Rerendering the Pageblock Table :
Please make the below changes in apex:Commandbutton ,apex:pageBlockTable :
<apex:page controller="AgendaBuilderController">
<apex:form >
<apex:pageBlock title="Agenda Builder">
<apex:outputLabel value="Select Attendee">
<apex:selectList multiselect="false" size="1">
<apex:selectOptions value="{!leadNames}">
</apex:selectOptions>
</apex:selectList>
</apex:outputLabel>
<apex:outputLabel value="Select Event">
<apex:selectList multiselect="false" size="1" value="{!selectedEvent}">
<apex:selectOptions value="{!campgnNames}">
</apex:selectOptions>
<apex:commandButton value="Go" action="{!showSessions}" reRender="abcd,PBT">
</apex:commandButton>
</apex:selectList>
</apex:outputLabel>
<apex:outputLabel value="{!selectedEvent}" id="abcd"></apex:outputLabel>
<apex:pageBlockTable value="{!displaySessions}" id="PBT" var="a" title="Session Details">
<apex:column value="{!a.Name}">
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks,
Maharajan.C
All Answers
Yor ReRendering the OutPut Label not Rerendering the Pageblock Table :
Please make the below changes in apex:Commandbutton ,apex:pageBlockTable :
<apex:page controller="AgendaBuilderController">
<apex:form >
<apex:pageBlock title="Agenda Builder">
<apex:outputLabel value="Select Attendee">
<apex:selectList multiselect="false" size="1">
<apex:selectOptions value="{!leadNames}">
</apex:selectOptions>
</apex:selectList>
</apex:outputLabel>
<apex:outputLabel value="Select Event">
<apex:selectList multiselect="false" size="1" value="{!selectedEvent}">
<apex:selectOptions value="{!campgnNames}">
</apex:selectOptions>
<apex:commandButton value="Go" action="{!showSessions}" reRender="abcd,PBT">
</apex:commandButton>
</apex:selectList>
</apex:outputLabel>
<apex:outputLabel value="{!selectedEvent}" id="abcd"></apex:outputLabel>
<apex:pageBlockTable value="{!displaySessions}" id="PBT" var="a" title="Session Details">
<apex:column value="{!a.Name}">
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks,
Maharajan.C
Thank you very much for your reply. Your solution worked.
Regards,
Rohit
Please Mark Best Answer !!! refer below how to mark.