You need to sign in to do that
Don't have an account?
Joe 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:
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; } }
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
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
Thanks,
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
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.