My data model:
I have a object called skill review which has skill__c,level__c as a lookup fields. I have a interview object which has skill review in a related list. I have a visualforce page where I have a level variable as a selectList. I would like the level(1-5) entered by the user to be updated in Level__c object of skill Review object. Below is my VF page and controller for that:
VF page:
<apex:page standardController="Interview__c" extensions="SkillReviewExtension" showHeader="false">
<apex:form >
<apex:pageBlock title="Candidate Skill Evaluation" id="skills_list">
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Edit" action="{!Edit}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{! SkillReview }" var="ct" >
<apex:column value="{! ct.Skill__c}"/>
<apex:column value="{! ct.Level__c}"/>
<apex:column headerValue="Level">
<apex:selectList value="{!Level}" multiselect="false" size="1" rendered="{!isEditMode}">
<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:outputText value="{!Level}"/>
</apex:column>
<apex:column headerValue="Description">
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class SkillReviewExtension{
private final Interview__c review;
public boolean isEditMode {get;private set;}
public String Level{get;set;}
List<SkillReview> skillReviewList;
public SkillReviewExtension(ApexPages.StandardController stdController) {
this.review= (Interview__c)stdController.getRecord();
}
public List<Skill_Review__c> getSkillReview() {
skillReviewList=new List<skillReview>();
List<Skill_Review__c> results = [SELECT Id,Name,Skill__c,Level__c FROM Skill_Review__c where Interview__c =:review.id ];
system.debug(results.size());
//Level=results[0].Level__r.Description__c;
//skillReviewList.skillReview[0]=results.clone();
return results;
}
public PageReference save(){
isEditMode=false;
return null;
}
public PageReference edit(){
isEditMode=true;
return null;
}
}