I have a VF controller (similar to the following) with two types of classes:

  1. Outer Wrapper Class benefitSection - to hold section data
  2. Inner Wrapper Class benefitChoice - to hold Line Item data

Within each section, there is a List<benefitChoice> called availableList. benefitChoice is a basic wrapper (boolean + record) to record which benefitChoices are selected.

I use an apex:repeat to loop over the availableList, but when I refresh the page using a commandAction (by using the method returnNull or one that actually does something meaningful), the benefitChoice's selelected values aren't setting to the controller. (After the refresh/reRender, ALL of the checkboxes are false whether or not they have been checked.)

All my class variables are public {get;set;}, and I thought the VF page will set all List variables back to the controller (but it won't honor maps). I'm kinda stuck at the moment.

VF Page:

        <apex:repeat value="{!medicalSection.availableList}" var="b">
                <apex:inputCheckbox value="{!b.selected}"/>
                <apex:outputField value="{!b.benefit.Item_Description__c}"/>
        <apex:commandButton action="{!returnNull}" value="Submit"/>


public Cntrlr_SelectWhatYouWant{
    public benefitSection medicalSection {get;set;}    
    public benefitSection dentalSection {get;set;}
    public benefitSection flexSection {get;set;}
    // etc...

    public benefitSection {  // OUTER wrapper 
         public string sectionRecordType {get;set;}
         list<benefitChoice> availableList {get;set;}

         public benefitSection(){
             this.availableList=new list<benChoice>();
         }//END init()

    }//END benefitSection

    public beneficChoice { // INNER wrapper  
        public boolean selected {get;set;}
        public Benefit__c benefit {get;set;}

        public benefitChoice(){ this.selected=false; this.benefit=new Benefit__c()} // END init()
        public benefitChoice(Benefit__c benefit){
        }//END init(Benefit__c benefit)
    }//END benefitChoice


    public Cntrlr_SelectWhatYouWant(){
        // initialize all of the benefitSections
        // and initialize each availableList within each benefitSection

    }//END init

    public pageReference returnNull(){
        return null;
    }//END returnNull()

}//END Cntrlr_SelectWhatYouWant

  • 1
    How are you processing your list of selections? If you just refresh the whole page (return null) it will reinitialize everything. Your Submit button, should do something to loop through the values and pull out the data.
    – JimRae
    Nov 5 '13 at 22:28
  • returning a null pageReference won't create a new instance of my controller, so I don't think the issue is with the submit Method. :) Nov 5 '13 at 22:39
  • Have you added a system.debug(medicalSection); within the returnNull method to verify that the member variables truly are not being set the way you expect? Also, Map collections work just as well as lists - but the syntax to iterate over and bind to Map data is a tiny bit more complicated.
    – Mark Pond
    Nov 5 '13 at 23:14

The following code works like I want it to (/think it should), so there's gotta be something wrong with my actual code (the code in the question is just a snippit of the real thing).

<apex:page controller="Cntrlr_testPage">
            width: 5rem; 
            height: 2rem;
            border:5px solid blue;

    <apex:form >
        <apex:repeat value="{!section1.innerList}" var="b">
            <div class="hi">
                <apex:inputCheckbox value="{!b.selected}"/>
            <div class="hi2" >
                <apex:outputText value="{!b.name}"></apex:outputText>
        <apex:commandButton action="{!doNothing}" value="Submit"/>


public class Cntrlr_testPage {

public outterClass section1 {get;set;}

public class outterClass{
    public string name {get;set;}
    public list<innerClass> innerList {get;set;}

    public outterClass(){
        this.innerList=new list<innerClass>();
        }//END init()  
    }//END outterClass

    public class innerClass{
        public boolean selected {get;set;}
        public string name {get;set;}

        public innerClass(){
        }//END init()

        public innerClass(string name){
        }//END init(string name)
    }//END innerClass

    public Cntrlr_testPage(ApexPages.StandardController con){

    }//END init(ApexPages.StandardController con)

    public Cntrlr_testPage(){
        this.section1=new OutterClass();
        list<innerClass> tmpInnerList=new list<innerClass>();
        for(integer i=0;i<5;i++)
            tmpInnerList.add(new InnerClass('#'+string.valueof(i+1)));
    }//ENd init()

    public pageReference doNothing(){
        return null;
    }//END doNothing    

}//END Cntrlr_testPage

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.