1
votes

I am an amateur developer looking for a unique solution that Google doesn't have an answer to.

I need to create a time-table for a class. There are 6 hours with 6 teachers assigned to each subject. For the subject that I select, the respective teachers should be shown in the corresponding list.

Refer the VF code below:

<b><i>{!$ObjectType.Class__c.fields.Firts_Hour_Subject__c.label}</i></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <apex:selectList size="1" multiselect="false" value="{!selectedSubject}">
            <apex:selectOptions value="{!Subject}"/>              
            <apex:actionSupport event="onchange" reRender="render1"/>
            </apex:selectList> 
             &nbsp;&nbsp;     
            <b><i>{!$ObjectType.Class__c.fields.First_Hour_Teacher__c.label}</i></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <apex:selectList size="1" multiselect="false" id="render1">
            <apex:selectOptions value="{!RelatedTeacher}"/>              
            </apex:selectList>

This repeats for a total of 6 times. I want to not create and pass 6 values, instead I want to use a single variable/array to pass the values to apex.

This is the apex code:

public class listReturn {

        public String SelectedSubject {get;set;}

//Other code.....

//This is the method that returns the list of teachers based on subjects.

public List<SelectOption> getRelatedTeacher(){
                    List<SelectOption> RelatedTeacher=new List<SelectOption>();
                    List<Teacher__c> teach = new List<Teacher__c>();
                    teach = [select Teacher__c.Name from Teacher__c where Teacher__c.Subject_del__r.Name = :SelectedSubject];
                    RelatedTeacher.add(new SelectOption('--SELECT TEACHER--','--SELECT TEACHER--'));
                    for(Teacher__c e:teach){
                        RelatedTeacher.add(new SelectOption(e.Name,e.Name));
                    }
                    return RelatedTeacher; 
        }
}

(Edit) here I want to achieve something similar to dependent lookup field that is available in customization..now with that in mind I'm trying to pass the value from the subject selectlist to {!selectedSubject} in apex..the problem I'm facing is that my final output only takes value of last selectlist and returns the teacher list for all of the other selectlists..I want to use the same {!selectedsubject} var and control the teacher list based on the input from the other subject selectlists.

Thanks in advance!

1

1 Answers

0
votes

You can use <apex:repeat> and drive it by a list of hours.