1

In my piece of code below, I use select list tag to get user's input for a field of an object. I have a text field type for an object which I am trying to update using a VF page.

                <apex:column headerValue="Rating" style="text-align:center;">

                    <apex:outputField value="{!skillreview.skillReview.RatingCopy__c}" rendered="{!NOT(interviewerMode)}"/>

                    <apex:selectList value="{!skillreview.rating}" multiselect="false" size="1" rendered="{!interviewerMode}" id="sl" >
                        <apex:selectOption itemValue="N/A" itemLabel="N/A"/>
                        <apex:selectOption itemValue="1" itemLabel="1"/>
                        <apex:selectOption itemValue="2" itemLabel="2"/>
                        <apex:selectOption itemValue="3" itemLabel="3"/>
                        <apex:selectOption itemValue="4" itemLabel="4"/>
                        <apex:selectOption itemValue="5" itemLabel="5"/>

                    </apex:selectList>

                </apex:column>

Description:

Once I hit save on my VF page , I can save the value to the database and I set the interviewerMode variable as false, which would show me <apex:outputField value="{!skillreview.skillReview.RatingCopy__c}" rendered="{!NOT(interviewerMode)}"/> and when I click an edit button(custom button which I am able to edit the page) , I make the interviewerMode variable as true, which would show me :

                <apex:selectList value="{!skillreview.rating}" multiselect="false" size="1" rendered="{!interviewerMode}" id="sl" >
                    <apex:selectOption itemValue="N/A" itemLabel="N/A"/>
                    <apex:selectOption itemValue="1" itemLabel="1"/>
                    <apex:selectOption itemValue="2" itemLabel="2"/>
                    <apex:selectOption itemValue="3" itemLabel="3"/>
                    <apex:selectOption itemValue="4" itemLabel="4"/>
                    <apex:selectOption itemValue="5" itemLabel="5"/>

                </apex:selectList>

The problem: When I hit edit the value of the field is reset back to "N/A" instead of the most recent value of the field that was updated to the field. How can I make the field to retain its value when I use selectList or selectionOption.

Controller:

public class InterviewattachmentPDFExtension{

    public Interview__c interview{get;set;}
    public boolean interviewerMode {get;private set;} // make it global, set to true when sending pdf
    public boolean interviewerMode1 {get;private set;}
    public Boolean disabl {get;set;}
    public Boolean disabl1 {get;set;}
    public String rating{get;set;}


    //public SkillReviewWrapperTest ratingskill{get;set;}
    public List<SkillReviewWrapperTest> SkillReviewList{get;set;}
    public List<SkillReviewWrapperTest> SkillReviewList1{get;set;}
     public List<SkillReviewWrapperTest> SkillReviewList2{get;set;}
     public String link {get;set;}
     public List<SelectOption> RatingList{get;set;}
    //public List<skillHelper> evaluationList{get;set;}
    public boolean rend{get;set;}
    public boolean rend1{get;set;}
    public ApexPages.StandardController standrdController;

    public InterviewattachmentPDFExtension(ApexPages.StandardController controller) {
        disabl1 = true;
        interview=(Interview__c)controller.getRecord();
        standrdController = new ApexPages.StandardController(interview);
        standrdController=controller; 
        interview=[select Job_Application__c,Image__c,Name__c,Interviewer_Feedback__c,Interviewed_Date__c,Interview_Mode__c,Interviewer_Name__c,Hiring_Manager__c, 
                      Years_Of_Experience__c,  Client_Name__c,Business_Unit__c,Recommendations__c,Interviewer_Emp_ID__c,Hiring_Manager_Copy__c,Additional_Interviewer__c,Fitment_Level__c, (select Name,Skill__r.Name,Level__r.Name,Recommended_Level_Description__c,Skill_Level_Description__c,RatingCopy__c from Skill_review__r) from Interview__c where id=:interview.id];

            if(interview.Image__c != NULL){
            String firstSubString = interview.Image__c.substringBetween('<img', 'img>');
            System.debug('First substring: ' + firstSubString);

            String secondSubString = firstSubString.substringBetween('src="', '"');
            System.debug('Second substring: ' + secondSubString);

            link = secondSubString.replace('amp;', '');
            System.debug('Link*************: ' + link);
         }

        if(ApexPages.currentPage().getParameters().get('interviewerMode') == NULL){
            interviewerMode= true;
        }else{
            interviewerMode = Boolean.valueOf(ApexPages.currentPage().getParameters().get('interviewerMode'));

        }

        interviewerMode1 = false;

        initSkillReviews(); 

    }

    public PageReference addErrorMessage() {
    ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Thanks for the FeedBack '));        
    return null;
    }

    private void initSkillReviews() {

        skillReviewList=new List<SkillReviewWrapperTest>();        
        for(Skill_Review__c sr: [SELECT Id,Name,Skill__c,Skill__r.Name,Level__c,Skill_Level_Description__c,Recommended_Level_Description__c,Rating__c,RatingCopy__c,Level_of_Skill__c FROM Skill_Review__c where Interview__c =:interview.id ]){              
            skillReviewList.add(new SkillReviewWrapperTest(sr));
        }

        skillReviewList1=new List<SkillReviewWrapperTest>();        
        for(Skill_Review__c sr1: [SELECT Id,Name,Skill__c,Skill__r.Name,Level__r.Name,Skill_Level_Description__c,Comments__c,Recommended_Level_Description__c,RatingCopy__c,Rating__c,Level_of_Skill__c FROM Skill_Review__c where Interview__c =:interview.id and Skill__r.Non_Technical_Skill__c=false]){              
            skillReviewList1.add(new SkillReviewWrapperTest(sr1));
        }

        skillReviewList2=new List<SkillReviewWrapperTest>();        
        for(Skill_Review__c sr1: [SELECT Id,Name,Skill__c,Skill__r.Name,Level__r.Name,Skill_Level_Description__c,General_Skill_Description__c,Comments__c,Recommended_Level_Description__c,RatingCopy__c,Rating__c,Level_of_Skill__c FROM Skill_Review__c where Interview__c =:interview.id and Skill__r.Non_Technical_Skill__c=true ORDER BY Skill__r.Name]){              
            skillReviewList2.add(new SkillReviewWrapperTest(sr1));
        }
      }    

      public pagereference editInterviewerFeedback(){   
      interviewermode = true;
      return null;
      }


    public pagereference saveInterviewerFeedback(){

        Map<String, String> skillAndLevel = new Map<String, string>();
        for(SkillReviewWrapperTest obj: skillReviewList1 )
        {
            skillAndLevel.put(obj.skillreview.skill__r.Name+obj.rating,obj.rating);
        }

        for(SkillReviewWrapperTest obj: skillReviewList2 )
        {
            skillAndLevel.put(obj.skillreview.skill__r.Name+obj.rating,obj.rating);
        }


        map<String, Id> mapLevelName = new map<String, Id>();
        for(Level__c ratingObj:[SELECT Skill_of_Level__c,Id, Name FROM Level__c WHERE Skill_And_Level__c IN: skillAndLevel.keyset() ])
        {
            mapLevelName.put(ratingObj.Skill_of_Level__c, ratingObj.Id);
        }

        List<Skill_Review__c > updateLevelInSkillReview= new List<Skill_Review__c>();    
        for(SkillReviewWrapperTest obj: skillReviewList1)
        {
            // put the level id in SkillreviewList's Level__c, to be updated in database
            // get the level id using the level name selected by user in picklist stored in SkillReviewList
            obj.skillReview.rating__c = mapLevelName.get(obj.skillReview.Level_of_Skill__c); 
            updateLevelInSkillReview.add(obj.skillReview);
        } 

        for(SkillReviewWrapperTest obj: skillReviewList2)
        {
            // put the level id in SkillreviewList's Level__c, to be updated in database
            // get the level id using the level name selected by user in picklist stored in SkillReviewList
            obj.skillReview.rating__c = mapLevelName.get(obj.skillReview.Level_of_Skill__c); 
            updateLevelInSkillReview.add(obj.skillReview);
        }    

        update updateLevelInSkillReview;

        standrdController.save();
        interviewerMode = false;
        interviewerMode1 = true;
         standrdController.save();
        rend=false;
        rend1=true;
        for(integer i =0 ; i<SkillReviewList1.size();i++){
        system.debug('&&&&&&&&&&&&&&&&&'+SkillReviewList1[i].rating);
        }
        pagereference pr = new pagereference('/apex/InterviewattachmentPDF?scontrolCaching=1&id='+interview.id+'&interviewermode=false');
        pr.setredirect(true);
        return pr;
    }

    public void falsemode(){
    interviewerMode=false;
    }

    public void sendEmail () { 

    OutboundEmails.SendEmailNotification(interview.id);
    }

    public pagereference edit(){
    interviewerMode = true;
    return null;
    }


}

SkillreviewwrapperTest:

public class SkillReviewWrapperTest{

    public Skill_Review__c skillReview{get;set;}

    public String rating{get;set;}


    public SkillReviewWrapperTest(Skill_Review__c skillReview){

         this.skillReview = skillReview;
         this.rating = skillReview.Rating__c;

    }

}
  • When you click save on the page, is it a rerender or a total refresh on the page? – Lance Shi Sep 27 '16 at 0:00
  • It is rendered when I click the save button. It is not full referesh. I use an id in the pageblock section table and rendered that id when I click the custom button – SfdcBat Sep 27 '16 at 0:05
  • Can you post your save method and edit method in your controller, please? Also, can you add a System.debug(skillreview.rating) in your edit method and see the result? I am almost sure it is null. But just want to be sure. – Lance Shi Sep 27 '16 at 0:09
  • @LanceShi Pls see the edit – SfdcBat Sep 27 '16 at 0:51
  • It could be a problem with the SkillReviewWrapperTest constructor. How is SkillReviewWrapperTest.rating being populated in a new wrapper? – Jeremy Nottingham Sep 27 '16 at 3:49
1

In the edit method, assign value from the query like this below:

public PageReference editMethod(){
//assign value from database
skillreview.rating = "1";
return null;
}

I have shown hard coded value "1" here

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.