I am trying to display a program name and a list of seminars connected to the program in a select list box in a vf page. I need to do it 5 times (5 fields) showing the same values so a student can choose up to 5 seminars if there are that many in a program.
I am getting an error when passing the two fields to the VF page (seminarItem and programName).
- What do I need to go to get the code to work?
- Is there an intelligent way to generate the same field 5 times but each field will be "mapped" to a separate field in the SF Object which means there is a field named seminar_1, seminar_2 and so on that need the seminar that the student chooses. Or should I just repeat the same apex:outputField 5 times.
Here is the VF:
<apex:page controller="vfCnt_chooseSeminar"> <apex:form > <apex:pageMessages />
<apex:pageBlock title="Choose Seminar(s) for " mode="edit">
<apex:pageBlockSection title="{!programName}" columns="2">
<apex:outputField label="Seminar Name:" value="{!seminarItem}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form> </apex:page>
Here is the controller:
public class vfCnt_chooseSeminar {
private string programID = '';
public List<Program__c> seminarItem{get;set;}
public String programName{get;set;}
public vfCnt_chooseSeminar()
{
//Constructor
List<Program__c> seminarList = new List<Program__c>();
programID = System.currentPageReference().getParameters().get('pId');
seminarList = [Select Seminar1__c,Seminar2__c,Seminar3__c,Seminar4__c,Seminar5__c,ID,Name From Program__c Where ID = :programID];
Set <String> sems = New Set <String>();
if(seminarList.isEmpty() == false)
{
for(Program__c record :seminarList)
{
sems.add((String) record.get('Seminar1__c'));
sems.add((String) record.get('Seminar2__c'));
sems.add((String) record.get('Seminar3__c'));
sems.add((String) record.get('Seminar4__c'));
sems.add((String) record.get('Seminar5__c'));
}
// seminarItem = seminarList;
seminarItem = sems;
programName = seminarList[];
}
else
{
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'The Program ID is invalid.');
ApexPages.addMessage(msg);
}
}
}