2

I have a page, Student.

enter image description here

Below in the Student Schedule, I can edit the Grade by double clicking on it and the page will update when I click save. When I update the list, I run a function that calculates the GPA. I can get the value in the object, but the page does not reflect the change until I refresh the page. Is there a way to rerender the page when I click the save button so that the GPA will show?

<apex:page standardController="Students__c" extensions="StudentCourseList">
    <apex:form >
        <apex:pageBlock title="Student Schedule" id="student_schedule">
        <apex:outputText value="{!message}" style="font-weight:bold;color:red" escape="false" />

            <apex:pageBlockTable value="{!courseDetails}" var="st">
                <apex:column >
                    <apex:commandLink action="{!deleteCourse}" value="Del" id="commandLinkDelete" >
                        <apex:param name="studentcourse_id" value="{!st.id}" assignTo="{!studentcourse_id}"/>
                    </apex:commandLink>
                </apex:column>
                <apex:column headervalue="Course" value="{!st.Course_Detail__r.FKCourse__r.Name}"/>
                <apex:column headervalue="Professor" value="{!st.Course_Detail__r.Professor__c}"/>
                <apex:column headervalue="Room" value="{!st.Course_Detail__r.FKRoom__r.Name}"/>
                <apex:column headervalue="DOW" value="{!st.Course_Detail__r.DOW_Abbr__c}"/>
                <apex:column headervalue="Start Date" value="{!st.Course_Detail__r.StartDate__c}"/>
                <apex:column headervalue="Grade">
                    <apex:outputfield value="{!st.Grade__c}">
                        <apex:inlineEditSupport event="ondblclick" resetfunction="callonCancelAction" showonedit="saveAccid, cancelAccId"></apex:inlineEditSupport>
                    </apex:outputfield>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:pageBlock >
            <apex:pageblockbuttons >
                <apex:commandbutton action="{!saveGrade}" id="SaveAccid" value="Save"></apex:commandbutton>
                    <apex:commandbutton id="cancelAccId" onclick="callonCancelAction()" value="Cancel"></apex:commandbutton>
            </apex:pageblockbuttons>
        </apex:pageBlock>   
    </apex:form>
</apex:page>

Code:

public class StudentCourseList {
    private ApexPages.StandardController controller {get; set;}
    public string studentcourse_id {get;set;}
    private Students__c s;
    public String message { get; set; }

    public StudentCourseList(ApexPages.StandardController controller){
    this.controller = controller;
    this.s = (Students__c)controller.getRecord();
    }

    public List<StudentCourseDtlAssc__c> courseDetails{
        get{
            System.debug('couseDetails Get');
            if(courseDetails == null){
                Id sId = s.Id;
                System.debug('sId:' + sId);
                courseDetails = Database.query(
                    'SELECT StudentCourseDtlAssc__c.Course_Detail__r.FKCourse__r.Name,'+
                    'StudentCourseDtlAssc__c.Id, ' +
                    'StudentCourseDtlAssc__c.Course_Detail__r.DOW_Abbr__c,' +
                    'StudentCourseDtlAssc__c.Course_Detail__r.Professor__c,' + 
                    'StudentCourseDtlAssc__c.Course_Detail__r.FKRoom__r.Name,' +
                    'StudentCourseDtlAssc__c.Grade__c,' +
                    'StudentCourseDtlAssc__c.Course_Detail__r.StartDate__c FROM StudentCourseDtlAssc__c ' +
                    'WHERE StudentCourseDtlAssc__c.Student__r.Id=:sId');
                System.debug(courseDetails);
            }
            System.debug(courseDetails);
            return courseDetails;

        }
        set;
    }
    public List<StudentCourseDtlAssc__c> getcourseDetails(){
        message += 'I am in';
        return CourseDetails;
    }
    public PageReference deleteCourse() {
        List<StudentCourseDtlAssc__c> deleteObj = [SELECT Id FROM StudentCourseDtlAssc__c WHERE StudentCourseDtlAssc__c.Id =:studentcourse_id];
        delete deleteObj;
        return null;
    }
    public PageReference saveGrade() {
        update CourseDetails;
        calcGPA();
        return null;
    }

    private void calcGPA() {
        system.debug('inGPA');
        Decimal total = 0;
        Integer count = 0;
        System.debug('StudentCourse ID: ' + studentcourse_id);
        Id sId = s.Id;
        List<StudentCourseDtlAssc__c> stGrades = [SELECT StudentCourseDtlAssc__c.Grade__c FROM StudentCourseDtlAssc__c WHERE StudentCourseDtlAssc__c.Student__r.Id=:sId];
        System.debug('Data: ' + stGrades);
        for(StudentCourseDtlAssc__c g: stGrades ) {
            count +=1;
            if(g.Grade__c == 'A') {
                System.debug('A');
                total += 4;
            }
            else if(g.Grade__c == 'B') {
                System.debug('B');
                total +=3;
            }
            else if(g.Grade__c == 'C') {
                System.debug('C');
                total +=2;
            }
            else if(g.Grade__c == 'D') {
                System.debug('D');
                total +=1;
            }
        }
        System.debug('Count: ' + count + ' Total: ' + total);
        s.GPA__c = total/count;
        System.debug('GPA: ' + s.GPA__c);
        update s;
    }
}
2
  • Please share your code and your approach so far .On Save you can refresh top frame ? Aug 1, 2015 at 20:47
  • i updated with my code
    – Peter Sun
    Aug 2, 2015 at 0:26

1 Answer 1

1

You can refresh the page using javascript. First you would need to add reRender on the commandButton so that you can call javascript after the save action is completed.

<apex:commandbutton action="{!saveGrade}" id="SaveAccid" value="Save" reRender="student_schedule" oncomplete="window.top.location = '/{!s.Id}';"></apex:commandbutton>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .