1

A part of VF page is below:

<apex:pageBlockSection title="EVALUATION">
    <apex:pageblockTable value="{!interviewSkillReviews}" var="skillreview">
        <apex:column headerValue="Parameters">  
            <apex:outputLabel value="ABC" />   
            <apex:outputLabel value="Hello" /> 
            <apex:outputLabel value="Test" /> 
            <apex:outputLabel value="XYZ" />
        </apex:column>
        <apex:column headerValue="Rating">                        
            <apex:selectList value="{!rating}" multiselect="false" size="1" rendered="{!interviewerMode}" >
                <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>
    </apex:pageblockTable>
</apex:pageBlockSection>

And it is rendered as:

enter image description here

The value in output text is just the field api name of the object Interview__c. I have 4 field value which I would like to display in each row and have a drop down selection for each on of them visible on the page. I am trying to get the data from user for each field and update it in the database using extension class. But struck here.also, I would like the label text to appear under the parameter column. I would like it to appear like:

enter image description here

9
  • Share your apex code as well. I think you are getting single records here. – Tushar Sharma Jun 1 '16 at 5:42
  • Well, the value in <apex:pageblockTable value="{!interviewSkillReviews}" var="skillreview"> are dummy. I am not using it inside the code. – SfdcBat Jun 1 '16 at 5:43
  • Then how can you expect four rows? They are required fields for a pageblocktable – highfive Jun 1 '16 at 5:46
  • Sorry I do not have fields to display there. I just want to display a text in each row and corresponding drop down option. Once the user selects the drop and press save , I should get the value of selected drop down and update the corresponding field using my extension. – SfdcBat Jun 1 '16 at 5:48
  • Please see the edit. – SfdcBat Jun 1 '16 at 5:51
3

I am not sure what is inside your interviewSkillReviews in your controller class. But in order to achieve your result, you will need something like this. In your apex controller:

List<skillHelper> interviewSkillReviews = new List<skillHelper>();
interviewSkillReviews.add(new skillHelper('ABC'));
interviewSkillReviews.add(new skillHelper('Hello'));
interviewSkillReviews.add(new skillHelper('Test'));
interviewSkillReviews.add(new skillHelper('XYZ'));

class skillHelper {
    public String review;
    public skillHelper (String review) {
        this.review = review;
    }
}

Then in your VF page:

<apex:pageBlockSection title="EVALUATION">

    <apex:pageblockTable value="{!interviewSkillReviews}" var="skillreview">
        <apex:column headerValue="Parameters">  
            <apex:outputLabel value="{skillreview.review}" />   
        </apex:column>

        <apex:column headerValue="Rating">                        
            <apex:selectList value="{!rating}" multiselect="false" size="1" rendered="{!interviewerMode}" >
                <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>

    </apex:pageblockTable>
</apex:pageBlockSection>

Apparently you need to adjust the code according to your requirement. But this should give you the idea on how to generate a table via pageBlockTable

7
  • Hello, Not sure why I get a null pointer exception at - interviewSkillReviews.add(new skillHelper('ABC')); – SfdcBat Jun 1 '16 at 6:37
  • @SfdcBat edited my apex code which previously doesn't even compile. I am not getting the exception you mentioned as I executed in anonymous block. Would you please try again with the updated version? – Lance Shi Jun 1 '16 at 6:42
  • I think you missed ! in <apex:outputLabel value="{!skillreview.review}" />, but I get an error - Error: Unknown property 'skillHelper.review'. Not sure why – SfdcBat Jun 1 '16 at 6:43
  • @SfdcBat true. I missed that !. For the error you have got, simply change review into a property by adding {get; set;} after the review definition and it will work for you – Lance Shi Jun 1 '16 at 6:56
  • Thanks. It worked. I can see the drop down now. I have a question though- I am trying to get the value of each drop down and update it 4 different fields - ABC,Test,Hello,XYZ. I was thinking to use the value of <apex:selectList value="{!rating}" in m controller to update each fields. But I have only one value for all the fields now, how can I get 4 values in 4 different variables so that I can update the fields. – SfdcBat Jun 1 '16 at 7:02
0
<apex:pageBlockSection title="EVALUATION">
<apex:pageblockTable value="{!interviewSkillReviews}" var="skillreview">
    <apex:column headerValue="Parameters">                                
      <apex:outputText label="Communication: Presentation of ideas, clarity of thought and expression" value="{!Interview__c.Communication__c}"/>
      <apex:outputText value="{!Interview__c.Attitude__c}"/>
    </apex:column>

   <apex:column headerValue="Rating">              
        <apex:repeat value='{!allfields}' var='field'>
            <apex:outputText label={!field.fieldname} value={!field.fieldname}/>
            <apex:selectList value="{!field.selectedValue}" multiselect="false" size="1" rendered="{!interviewerMode}"  >
                <apex:selectOptions value="{!field.selectListOfValues}"/>               
             </apex:selectList>     
         </apex:repeat>
   </apex:column>
    </apex:pageblockTable>
    </apex:pageBlockSection>



   public fieldandparamater
{
    Interview__c interview{get;set;}
    List<wrapper> allfields{get;set;}
    fieldandparamater(ApexPages.StandardController controller)
    {
        interview = (Interview__c)controller.getRecord();
        interview = [Select fields from Interview__c]
        allfields = new  List<wrapper>();
        String[] fieldnames = new String[]{'Field1__c','Field2__c','Field3__c',Field4__c'}; 
        for(String s: fieldnames)
        {
            allfields.add(s);
        }
    }
    public pagereference save()
    {
        Sobject inter_sobj = interview;
        for(wrapper field:allfields)
        {
            inter_sobj.put(field.fieldname,field.selectedValue)
        }
        update inter_sobj;
    }
    class wrapper
    {
        public String fieldname{get;set;}
        public String selectedValue{get;set;}
        public List<SelectOption> selectListOfValues{get;set;}
        wrapper(String fieldname)
        {
            this.fieldname = fieldname;
            this.selectedValue = selectedValue;
            selectListOfValues = picklistvalues();
        }
        public List<SelectOption> picklistvalues() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('1','1'));
            options.add(new SelectOption('2','2'));
            options.add(new SelectOption('3','3'));
            options.add(new SelectOption('4','4'));
            options.add(new SelectOption('5','5'));
            return options;
        }
    }
}

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.