3

Here is the VF page:

<apex:page controller="rateQuestionsControllers">
    <apex:form >
        <apex:pageBlock >
            <apex:pageblockTable value="{!rateWrappers}" var="sWrapper">
                <!-- reference the sObject in the wrapper and get its name -->
                <apex:column value="{!sWrapper.theRatingRecord.Name}" />
                <apex:column headerValue="Rate">
                    <!-- where we are going to store this row's selected proficiency -->
                    <apex:selectRadio value="{!sWrapper.rating}">
                        <apex:selectOptions value="{!RatingSelected}" /> 
                    </apex:selectRadio>
                </apex:column>
            </apex:pageblockTable>
        </apex:pageBlock>
        <apex:pageBlock >

        </apex:pageBlock>
    </apex:form>
</apex:page>

This is the controller:

Public Class rateQuestionsControllers{
public class rateWrapper{
public Customer_Rating__c theRatingRecord{get;set;}
public Integer rating { get; set; }
}

public List<rateWrapper> rateWrappers { get; set; } 

public rateQuestionsControllers(){
     // new up the list for the wrappers
       rateWrappers = new List<rateWrapper>();
 for (Customer_Rating__c rate : [SELECT Id, Name FROM     Customer_Rating__c]) {
            rateWrapper sWrapper = new rateWrapper();
            sWrapper.theRatingRecord = rate;
            sWrapper.rating = 0; // a default selection (blank)
        }
}


public List<SelectOption> getRatingSelected() {

        List<SelectOption> options = new List<SelectOption>();

        options.add(new SelectOption('bad','0'));

        options.add(new SelectOption('good','5'));
        options.add(new SelectOption('Excellent','10'));

        return options;
}

    public PageReference submit() {

     List<Customer_Rating__c> ratedetailslist = new List<Customer_Rating__c>()
        for (rateWrapper sWrapper: rateWrappers) {

            // only do the work if a value was selected
            if (sWrapper.rating!= 0) {
                Customer_Rating__c cr = new Customer_Rating__c();
                cr.Customer_name__c = sWrapper.theRatingRecord.Id;
                cr.Rating__c = sWrapper.rating;
                ratedetailslist.add(cr);    
            }

        }
        system.debug('-----rate---'+ratedetailslist);
        insert ratedetailslist;
        return null;
    }


}
  • public Integer rating { get; set; } make this String variablepublic String rating { get; set; } then sWrapper.rating = 0; change this to sWrapper.rating = '0'; – Ankuli Aug 16 '16 at 8:28
  • This not worked – Jill_sfdc Aug 22 '16 at 4:15
1

You have not added your rateWrapper to its list inside the constructor.

public rateQuestionsControllers(){
         // new up the list for the wrappers
     rateWrappers = new List<rateWrapper>();
     for (Customer_Rating__c rate : [SELECT Id, Name FROM Customer_Rating__c]) {
                rateWrapper sWrapper = new rateWrapper();
                sWrapper.theRatingRecord = rate;
                sWrapper.rating = 0; // a default selection (blank)
          rateWrappers.add(sWrapper);
        }
}
| improve this answer | |
  • Still radio buttons are not visible – Jill_sfdc Aug 22 '16 at 4:00
  • Do you have have Customer rating records in your org. What output you are getting with this code? The code with above modification works for me. – Anjuna Baby Aug 22 '16 at 9:51

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.