0

The checkbox will check if the time(picklist) entered for the teacher is still available. if it isnt, there will be an error. please check my code. my error is Error: Compile Error: unexpected token: ':' at line 56 column 127 in my controller and may not be used within an iterable component. You can use to define parameters for the function and pass iteration-specific values via the parameters. in VFP

VFP

<apex:page controller="wrapper_test_controller">
    <apex:form >
        <apex:pageblock tabStyle="Parent__c" >

                 <strong>   Welcome  {!$User.FirstName} {!$User.LastName}!
                    <apex:outputLabel style="float:right" > Date: {!MONTH(TODAY())}/ {!DAY(TODAY())}/ {!YEAR(TODAY())} </apex:outputLabel>
                 </strong>
                    <br></br>
                    <br></br>

         <apex:pageblocktable value="{!schedules}" var="schedule">
          <apex:column headerValue="Teacher" value=" {!schedule.tlname}, {!schedule.tfname}" />
          <apex:column headerValue="Subject" value="{!schedule.tsubject}"/>
          <apex:column headerValue="Room Assignment" value="{!schedule.room}"/>
          <apex:column headerValue="Time" >
          <apex:selectList value="{!schedule.oras}" multiselect="false" size="1">
             <apex:selectOption itemValue="9:00 AM" itemLabel="9:00 AM"/>
             <apex:selectOption itemValue="10:00 AM" itemLabel="10:00 AM"/>
             <apex:selectOption itemValue="11:00 AM" itemLabel="11:00 AM"/>
             <apex:selectOption itemValue="1:00 PM" itemLabel="1:00 PM"/>
             <apex:selectOption itemValue="2:00 PM" itemLabel="2:00 PM"/>
             <apex:selectOption itemValue="3:00 PM" itemLabel="3:00 PM"/>
             <apex:selectOption itemValue="4:00 PM" itemLabel="4:00 PM"/>
             <apex:selectOption itemValue="5:00 PM" itemLabel="5:00 PM"/>
          </apex:selectList>  
          </apex:column>
          <apex:column headerValue="Check Time" >
              <apex:inputCheckbox  id="chkbx" value="{!schedule.chkbx}"/>
                  <apex:actionFunction id="chk"  name="check" action="{!checkTime}"/>
     </apex:column>
          </apex:pageblocktable>

         <br/>       
        </apex:pageblock>
    </apex:form>
</apex:page>

Controller

public with sharing class wrapper_test_controller {
    public list<sched> schedules{get;set;}

     public wrapper_test_controller(){
     schedules = new List<sched>();

    list<teacher__c> object1 = [select id,name, First_name__c, Subject__c, Room_assignment__c from teacher__c ];

    list<schedule__c> object2 = [Select id, name, teacher__c, time__c, student__c, parent__c from schedule__c ];

    for(teacher__c teacher : object1){
        schedules.add(new sched(teacher));
    }
    for (schedule__c oras: object2){
        schedules.add(new sched(oras));
    }

}
public class sched{
    public Id tid {get;set;}
    public Id sid {get;set;}
    public Name sname {get;set;}
    public string steacher{get;set;}
    public string tlname{get;set;}
    public string tfname{get;set;}
    public string sparent{get;set;}
    public string sstudent{get;set;}
    public string oras{get;set;}
    public string room{get;set;}
    public string tsubject{get;set;}


public sched(teacher__c object1){
this.tid = object1.id;
this.tlname = object1.name;
this.tfname = object1.first_name__c;
this.tsubject = object1.subject__c;
this.room = object1.room_assignment__c;
}
public sched(schedule__c object2){

this.sid = object2.id;
this.steacher = object2.teacher__c;
this.oras= object2.time__c;
this.sstudent =object2.student__c;
this.sparent =object2.parent__c;

}
}


public class checkTime {
    public list<schedTime> schedule{get;set;}
    List<schedule__c> object2 = [Select id, name, teacher__c, time__c, student__c, parent__c from schedule__c WHERE teacher__c : schedule.teacher && time__c = schedule:oras];

       for (schedule__c time1: object2){
        schedules.add(new sched(time1));

    if(.size() > 0){
   apexPages.addmessage(new ApexPages.message(Apexpages.severity.error, 
   'Please select another time. this  time already taken.'));
   }

   }

   public class schedTime{
    public Id tid {get;set;}
    public string teacher {get;set;}

   }

   public sched(schedule__c schedule){

    this.sid = schedule.id;
    this.steacher = schedule.teacher__c;
}
}
0

Your code is hardly readable, but I tried to make it compile.

Use actionSupport instead of actionFunction inside of iterative components. For other errors read carefully error description and fix them in appropriate way.

<apex:page controller="wrapper_test_controller">
    <apex:form >
        <apex:pageblock >

                 <strong>   Welcome  {!$User.FirstName} {!$User.LastName}!
                    <apex:outputLabel style="float:right" > Date: {!MONTH(TODAY())}/ {!DAY(TODAY())}/ {!YEAR(TODAY())} </apex:outputLabel>
                 </strong>
                    <br></br>
                    <br></br>

         <apex:pageblocktable value="{!schedules}" var="schedule">
          <apex:column headerValue="Teacher" value=" {!schedule.tlname}, {!schedule.tfname}" />
          <apex:column headerValue="Subject" value="{!schedule.tsubject}"/>
          <apex:column headerValue="Room Assignment" value="{!schedule.room}"/>
          <apex:column headerValue="Time" >
          <apex:selectList value="{!schedule.oras}" multiselect="false" size="1">
             <apex:selectOption itemValue="9:00 AM" itemLabel="9:00 AM"/>
             <apex:selectOption itemValue="10:00 AM" itemLabel="10:00 AM"/>
             <apex:selectOption itemValue="11:00 AM" itemLabel="11:00 AM"/>
             <apex:selectOption itemValue="1:00 PM" itemLabel="1:00 PM"/>
             <apex:selectOption itemValue="2:00 PM" itemLabel="2:00 PM"/>
             <apex:selectOption itemValue="3:00 PM" itemLabel="3:00 PM"/>
             <apex:selectOption itemValue="4:00 PM" itemLabel="4:00 PM"/>
             <apex:selectOption itemValue="5:00 PM" itemLabel="5:00 PM"/>
          </apex:selectList>  
          </apex:column>
          <apex:column headerValue="Check Time" >
              <apex:inputCheckbox id="chkbx" value="{!schedule.chkbx}"/>
                  <apex:actionSupport id="chk" action="{!checkTime}"/>
             </apex:column>
          </apex:pageblocktable>

         <br/>       
        </apex:pageblock>
    </apex:form>
</apex:page>

controller

public with sharing class wrapper_test_controller {

    public PageReference checkTime() {
        return null;
    }

    public list<sched> schedules{get;set;}

     public wrapper_test_controller(){
     schedules = new List<sched>();

    list<teacher__c> object1 = [select id,name, First_name__c, Subject__c, Room_assignment__c from teacher__c ];

    list<schedule__c> object2 = [Select id, name, teacher__c, time__c, student__c, parent__c from schedule__c ];

    for(teacher__c teacher : object1){
        schedules.add(new sched(teacher));
    }
    for (schedule__c oras: object2){
        schedules.add(new sched(oras));
    }

}
public class sched{
    public Id tid {get;set;}
    public Id sid {get;set;}
    public Name sname {get;set;}
    public string steacher{get;set;}
    public string tlname{get;set;}
    public string tfname{get;set;}
    public string sparent{get;set;}
    public string sstudent{get;set;}
    public string oras{get;set;}
    public string room{get;set;}
    public string tsubject{get;set;}
    public string chkbx{get;set;}

public sched(teacher__c object1){
this.tid = object1.id;
this.tlname = object1.name;
this.tfname = object1.first_name__c;
this.tsubject = object1.subject__c;
this.room = object1.room_assignment__c;
}
public sched(schedule__c object2){

this.sid = object2.id;
this.steacher = object2.teacher__c;
this.oras= object2.time__c;
this.sstudent =object2.student__c;
this.sparent =object2.parent__c;

}
}


public class checkTime {
    public list<schedTime> schedule{get;set;}
    checkTime () {
        String teacher1 = 'teacher1';
        String tim1 = 'time1';
        List<schedule__c> object2 = [Select id, name, teacher__c, time__c, student__c, parent__c from schedule__c WHERE teacher__c = :teacher1  AND time__c = :tim1 ];
        List<schedTime> schedules = new List<schedTime>();
        for (schedule__c time1: object2){
            schedules.add(new schedTime(time1));
        }
        if(schedules.size() > 0){
           apexPages.addmessage(new ApexPages.message(Apexpages.severity.error, 
           'Please select another time. this  time already taken.'));
        }
    }
}


   public class schedTime{
        public Id tid {get;set;}
        public string teacher {get;set;}



       public schedTime(schedule__c schedule){

            this.tid = schedule.id;
            this.teacher = schedule.teacher__c;
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.