Problem with binding inputField to VisualForce

I get strange results on a Visualforce page (yes, Salesforce.com is not good, I know). My problem is that I am trying to use inputField to bind data to a custom sObject, but in my custom controller it does not recognize user input.

Here is the code snippet from the page:

<apex:pageBlockSection title="Enter New Fee" rendered="{!isRenderedFees}" > <apex:inputField value="{!workingFee.Fee_Type__c}" required="True"/> <apex:inputField value="{!workingFee.Fee__c}" required="True"/> <apex:pageBlockSectionItem > <apex:CommandButton value="Save Fee" action="{!saveFee}" immediate="true" /> <apex:CommandButton value="Cancel" action="{!cancelFee}" immediate="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> 

and here is the code from the controller:

 public Fee__c workingFee {get; set;} .... public PageReference saveFee(){ this.workingFee.Trade_Group__c = tradeGroup.id; try{ System.debug('~~~~#~~#~~workingFee: '+workingFee.Fee_Type__c +'='+workingFee.Fee__c); upsert workingFee; }catch (System.Dmlexception e){ ApexPages.addMessages(e); return null; } System.debug('~~~~#~~#~~workingFee: '+workingFee.Fee_Type__c +'='+workingFee.Fee__c); //savedFees.add(workingFee.clone()); //re-render the page this.isRenderedFees = False; return null; } 

I made sure that the workFee property is not null. Whenever I click the "Save Board" button after entering the values, it reloads the page and gives me the message "Error: required fields are missing: [Fee__c]" (note, Fee__c here - the currency field is not what it expects, what will it be sObject, right?)

The debug statement in the saveFee () method shows that the important workingFee fields are NULL when I expect them to be assigned the values ​​entered by the user.

+4
source share
2 answers

I had a whole bunch of problems connecting controls to an object opened with a simple {get; set; } notation ... The rest of your code will see the properties, but for some strange reason, your view will not (always) bind ...

Try writing explicit get / set methods like

 private workingFee; public Fee__c getWorkingFee() { return workingFee; } public void setWorkingFee(Fee__c value) { workingFee = value; } 

There is no logical reason why this should work differently than

 public Fee__c workingFee { get; set; } 

but in my experience he sometimes does ...

what did you say about this, what is icky ?;)

+10
source

Immediate = false / true has bitten me quite a few times. Good booty Yang.

0
source

All Articles