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
jmarinchakjmarinchak 

inputfield - passing values to controller

I'm probably doing something very wrong that is obvious to others but, it's not obvious to me.  Have a look and let me know if you see the problem.  I'm trying to do a quick quota calculation based on orders in the system (we use Scribe to pull orders from our ERP system).  In the user interface, the sales person just enters their quota amount and variable salary. 

Key problem is that the inputfield does not seem to be getting values from the user.

Thanks.

First my controller -

Code:
public class MyCommissionController {

    public Commission__c MyComm {get; set;}
    public Commission__c getMyComm() {
        return MyComm;
    }
 
    //Our collection of the class/wrapper objects cCommission
    private List<cCommission> CommissionList {get; set;}
    public List<cCommission> getCommission(){
        return CommissionList;
    }
    //This method uses a simple SOQL query to return a List of Contacts
    public PageReference getNumbers(){
        if(CommissionList == null){
            CommissionList = new List<cCommission>();
        
            for(SCRB_Salesorder__c c : [Select Customer_PO_Number__c, Name, Amount__c FROM SCRB_SalesOrder__c 
                              WHERE DocumentDate__c  > 2008-10-01]){
                /* As each contact is processed we create a new cContact object and
                add it to the contactList */
                CommissionList.add(new cCommission(c));
            }
        }
        return null;
    }
    
    /* New wrapper class */
    public class cCommission{
        public SCRB_Salesorder__c corder {get; set;}
        public Double Commission_Amount{get; set;}
        
        /*This is the contructor method. When we create a new cCommission object we pass a 
        SCRB_Salesorder_c that is set to the corder property. We also set the Commission_Amount value to zero*/
        public cCommission(SCRB_Salesorder__c c){
            corder = c;
            //if (myquota > 0) {
                /* Commission_Amount = c.Amount__c * myvariable / myquota; */
                Commission_Amount = c.Amount__c * 0.10;
            //} else {
            //    Commission_Amount = 0.0;
            // }
        }
    }
}

 Now the visualforce page:

Code:
<apex:page controller="MyCommissionController"> 
<apex:form >

  <apex:pageBlock title="Inputs" id="WholePage">
      <p><b>Report for {!$User.FirstName} {!$User.LastName}</b></p> <br />
      
      <b>Quota </b>
      <apex:inputField value="{!MyComm.Quota__c}" /> <br />
      
      <b>Variable Salary </b>
      <apex:inputField value="{!MyComm.Variable_Salary__c}" /> <br /><br />
      
      <apex:commandButton action="{!getNumbers}" value="Calculate" rerender="WholePage" status="status"/> <br />
      <apex:pageMessages ></apex:pageMessages>
  </apex:pageBlock>
  
  <apex:actionStatus startText="Updating..." id="status"/>
  
  <apex:pageBlock title="Orders" rendered="{!NOT(ISNULL(MyComm.Quota__c))}" >
  <apex:dataTable value="{!Commission}" var="aOrder" width="100%">
     <apex:column>
      <apex:facet name="header"><b>PO Number</b></apex:facet>
      {!aOrder.corder.Customer_PO_Number__c}
     </apex:column>
     <apex:column >
      <apex:facet name="header"><b>Name</b></apex:facet>
      {!aOrder.corder.Name}
     </apex:column>
     <apex:column >
      <apex:facet name="header"><b>Amount</b></apex:facet>
      {!aOrder.corder.Amount__c}
     </apex:column>
     <apex:column >
      <apex:facet name="header"><b>Commission</b></apex:facet>
     {!aOrder.Commission_Amount}
     </apex:column>
   </apex:dataTable>                
   </apex:pageBlock>

</apex:form>

</apex:page>

 


Jeff


mtbclimbermtbclimber
You need to instantiate the MyComm object, try this property definition instead:

Code:
public Commission__c MyComm {
    get {
        if(myComm == null) {
            myComm = new Commission__c();
        }
        return myComm;
    }
    set;
}

 Also, if you want this property to be public then I don't think you need the getter method that returns this property, i.e. you can remove this:

Code:
public Commission__c getMyComm() {
   return MyComm;
}

as you can bind directly to properties which has the same behavior as a getter method.

You might also want to check out pageBlockSection and the convenient behavior of inputField when nested in a pageblockSection unless you are avoiding it specifically.  Same goes for pageBlockTable instead of dataTable in which case you can avoid all the facet stuff and just bind the column's value attribute directly to your fields as it behaves like outputField which will give you automatic formatting for dates/currencies/numbers etc in addition to pulling each field's label out into the column header.




Message Edited by mtbclimber on 01-11-2009 12:45 PM
jmarinchakjmarinchak
Thanks  for the fast response.  I do need to check out the PageBlockSection capabilities. 

I've added your change.  Now, I've uncommented the references to MyComm in my code but, I get this error:

Error: Compile Error: Variable does not exist: MyComm.Variable_Salary__c at line 47 column 50.
Code:
        public cCommission(SCRB_Salesorder__c c){
            corder = c;
            if (MyComm.Quota__c > 0) {
                /* Commission_Amount = c.Amount__c * myvariable / myquota; */
                Commission_Amount = 0.0;
           } else {
               Commission_Amount = c.Amount__c * MyComm.Variable_Salary__c / MyComm.Quota__c;
            }
        }

 

My custom object Commission__c includes Variable_Salary__c and Quota__c. 

Can I access the MyComm values throughout the controller?

Jeff
mtbclimbermtbclimber
Normally yes but not from within a nested class.  You'll need to pass the information into the nested class either through the constructor or setting the value after constructing the nested class instance.