function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Joe Xu 7Joe Xu 7 

Input field value not binding to wrapper class

I'm trying to pass value for <apex:inputField> to wrapper class, but it doesn't work. The form does show the data from wrapper class which I think the get() is working but not the set(). I have turned on debug log and none of the changes (on the input field) has been passed on to the controller. Could someone point out where the problem is?

VF page:
<apex:pageBlockSection title="Meal Options" columns="1">
                <!-- Choose which product family-->
                <apex:actionRegion >
                    <apex:selectList value="{!SelectedProdFamily}" multiselect="false" size="1">
                        <apex:actionSupport event="onchange" action="{!applyFilter}" reRender="myProdList"/>
                        <apex:selectOptions value="{!ProdFamily}" > 
                            Product Family:  
                        </apex:selectOptions>
                    </apex:selectList>
                </apex:actionRegion>
                
                <!-- Product options table with pagination -->
                <apex:pageBlock >
                    <!--Table of available products and quantity -->
                    <apex:pageBlockTable value="{!selectProds}" var="sp" align="center" id="myProdList">
                         <!-- below is the input field which doesn't pass on the value to the binding wrapper class-->
                        <apex:column headerValue="Quantity">
                            <apex:inputField value="{!sp.mItem.Quantity__c}" required="true"/>
                        </apex:column>
                        <apex:column value="{!sp.pd.name}"/>
                        <apex:column value="{!sp.pd.Family}"/>
                        <apex:column value="{!sp.pd.Grams_of_Protein__c}"/>
                        <apex:column value="{!sp.pd.Grams_of_Fat__c}"/>
                        <apex:column value="{!sp.pd.Grams_of_Carbohydrates__c}"/>
                        <apex:column value="{!sp.pd.Quantity_Remaining__c}" />
                    </apex:pageBlockTable>
                    <!-- Button panel for product form-->
                    <apex:pageBlockButtons location="bottom">
                        <apex:outputPanel id="myButtons">
                            <apex:commandButton action="{!First}" title="First" value="|<First" disabled="{!disablePrevious}" reRender="myProdList,myButtons"/>
                            <apex:commandButton action="{!Previous}" title="Previous" value="Previous" disabled="{!disablePrevious}" reRender="myProdList,myButtons"/>
                            Page {!pageNumber} of {!totalPages}
                            <apex:commandButton action="{!Next}" title="Next" value="Next" disabled="{!disableNext}" reRender="myProdList,myButtons"/>
                            <apex:commandButton action="{!Last}" title="Last" value="Last>|" disabled="{!disableNext}" reRender="myProdList,myButtons"/>
                        </apex:outputPanel>
                    </apex:pageBlockButtons>
                </apex:pageBlock>
            </apex:pageBlockSection>
Controller:
public PageReference applyFilter(){
        
        Meal_Item__c temp = new Meal_Item__c();
        if(MealItems.size()>0){
            For(ProductOptionData p : SelectProds){
                    system.debug('test'+p.pd.id);
                    system.debug('test'+p.mItem.Quantity__c);
            }
        }
        SelectProds = SelectProds();
        return null;
    }

//Wrapper class
    Public class productOptionData{
        Public Product2 pd{get;set;}
        Public Meal_Item__c mItem{get;set;}
        
        public productOptionData(Product2 pd, Meal_Item__c mItem){
            this.pd = pd;
            this.mItem = mItem;
        }
    }


 
Best Answer chosen by Joe Xu 7
Joe Xu 7Joe Xu 7
Hi GauravGrag,

Thanks for the information. I have figured out the problem which is due to the incorrect way of using pageBlock, pageBlockSection and pageBlockSectionItem. Once updated, it works well without using any JS coding. 

All Answers

GauravGargGauravGarg
Hi Joe,

Use <Apex:function> to pass value to controller side and assign it Wrapper class. Please find below articles on apex:functions. 

https://developer.salesforce.com/forums/?id=906F0000000BTIPIA4

Hope this helps.

Thanks,
Gaurav
Joe Xu 7Joe Xu 7
Hi Gaurav, thanks for the information. Using apex:actionFunction is just another way to call function from Controller side. My problem is the inputField: sp.mItem.Quantity__c is not binding to the wrapper class so the value put in the VF form doesn't pass to controller. Any idea on why it's happening?

Thanks,
Joe
GauravGargGauravGarg
Hi Joe,

We can use two approach:
1, onClick(): if we want to bind VF page with Controller on button click. 
2. onChange(): if we want o bind VF page with Controller on value change in input field, using onChange() property. 

Hope this helps!!!

Thanks,
Gaurav
Skype: gaurav62990
Joe Xu 7Joe Xu 7
Hi GauravGrag,

Thanks for the information. I have figured out the problem which is due to the incorrect way of using pageBlock, pageBlockSection and pageBlockSectionItem. Once updated, it works well without using any JS coding. 
This was selected as the best answer