1

What I'm trying to do: at the onblur event for an inputField, I want to update an outputText based on the contents of that inputField.

Here is my code:

<apex:page standardController="Opportunity" extensions="opptyLineItem_EditAll2" id="page">
  <apex:form id="form">
    <apex:pageBlock title="{!$ObjectType.Product2.LabelPlural} (Standard {!$ObjectType.PriceBook2.Label})" id="dc" rendered="{!$ObjectType.Opportunity.accessible}">
      Change any of these fields and tab out of them to see the calculation take place. Click Save when satisfied.<p/>
      <apex:pageBlockTable value="{!Opportunity.OpportunityLineItems}" var="li" id="table">
        <apex:column headerValue="Number of Seats">
          <apex:inputField value="{!li.quantity}" id="numberOfSeats" >
            <apex:actionSupport event="onblur"
                                action="{!incrementCounter}"
                                rerender="counter" status="counterStatus">
              <apex:param name="numberOfSeats" value="{!li.quantity}" assignTo="{!liQuantity}"/>
            </apex:actionSupport>
          </apex:inputField>
          <apex:facet name="footer" >
              <span style="float:right;">Totals:</span> 
          </apex:facet>
        </apex:column>
        <apex:column headerValue="Total List Price">
          <apex:outputpanel id="counter">
            <apex:outputText value="{!count}"/>
          </apex:outputpanel>
        </apex:column>
      </apex:pageBlockTable>
    </apex:pageBlock>
  </apex:form>
</apex:page>

And the controller:

public class opptyLineItem_EditAll2 {
    public Opportunity oppty {get;set;}
    public Double liQuantity {get;set;}

    public opptyLineItem_EditAll2(ApexPages.StandardController stdController) { }

    Integer count = 0;

    public PageReference incrementCounter() {
            count++;
            return null;
    }

    public Double getCount() {
        System.debug('>>> I am here ' + liQuantity);
        //System.debug('>>> Oppty Id: ' + oppty.Id);
        return count;
    }
}

What works: I see the outputText being updated with the counter.

What doesn't work: I can't seem to get the current quantity and set it in the liQuantity property in the controller, and I can't seem to set the Opportunity object (oppty) in the controller. If I uncomment the second System.debug, I get an NPE.

Help?

1
  • 2
    map VF opportunity with controller: public opptyLineItem_EditAll2(ApexPages.StandardController stdController) { this.oppty = (Opportunity)stdController.getRecord(); } Commented Jun 25, 2016 at 16:44

1 Answer 1

1

I can't seem to get the current quantity and set it in the liQuantity property in the controller, and I can't seem to set the Opportunity object (oppty) in the controller. If I uncomment the second System.debug, I get an NPE.

This is because you don't get these values at the time you incrementCounter. I'm a bit surprised that you see the output text being updated with "counter" since count isn't declared as public and your variable count is declared simply as integer count, not public double count. Perhaps it's the output text that allows that to happen. Otherwise, it seems that you have both a type and visibility/access mismatch.

Your oppty.Id is null because public Opportunity oppty is an object. You've not utilized your controller's constructor to determine the Id from the opportunity object, nor have you passed the record Id to your controller from the page instead of the object itself. Doing either of those would solve the issue you're having with it being null.

Edit:

Try changing your constructor to something like:

public opptyLineItem_EditAll2(ApexPages.StandardController stdController) 
{  
    this.oppty = (Opportunity)stdController.getRecord(); 
}

You've declared you controller as an extension, but haven't passed the Id to it. That's what the above does.

2
  • Thanks for your time in answering. Could you help me understand how to get these values when we incrementCounter. I clearly am missing something fundamental, but I don't understand what is it...
    – cethegeek
    Commented Jun 25, 2016 at 16:45
  • 1
    See the above edit. That should allow the controller to recognize the object variable and populate the Id for oppty.
    – crmprogdev
    Commented Jun 25, 2016 at 18:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .