3

Have some inputText fields and I'm doing some calculations with the values of these(inputFields are inside a pageblocktable, having wrapper items).

VF :

<apex:actionFunction name="calculateTotals" action="{!calculateTotals}" rerender="pnlSummary,errorMessagesinvoicePage"/>
<apex:inputText onchange="calculateTotals()" value="{!item.quantity}" ></apex:inputText>

Controller :

public void calculateTotals(){
        strInvoicePageErrorMessages = '';
        if(this.invoice != null){
            Double total, gst, subTotal = 0;
            for(InvoiceItemWrapper wrapper : invoiceItemWrapperList){
                try{
                    System.debug('cost:'+wrapper.itemCost + ' : quantity:'+wrapper.quantity);
                    subTotal += (wrapper.itemCost * wrapper.quantity);
                }
                catch(Exception e){
                    System.debug('ERROR ' + e.getMessage() + ' : ' + e.getTypeName() );
                    if(e.getTypeName().contains('MathException') || e.getTypeName().contains('NullPointerException')){
                        strInvoicePageErrorMessages = 'Invalid values for quantity or item cost';
                        return;
                    }
                }
            }
        }
    }

Now the problem is actionFunction getting fired for onchange event but it's not binding the values for wrapper items;they have their first load values. Ok I'll try an alternative if this is what you can expect from JavaScript-Apex combination.

But for a inputCheckBox it's binding the value correctly. Why is that?

<apex:actionFunction name="toggleSelectSchedules" action="{!toggleSelectAllSchedules}" rerender="pnlSearchResult" >
          </apex:actionFunction>
<apex:inputCheckbox styleClass="selectAll" value="{!selectAllSchedules}" onchange="toggleSelectSchedules();" id="ckbCheckAll" />

selectAllSchedules is binding correctly in the controller.

What I'm guessing is component we are triggering the event should have unique id. But it needs a dynamic id generation inside a pageblocktable

EDIT : No immediate=true, actionRegion or required field missing etc. It's just not assigning the user input value for inputText at the controller wrapper instance. The same working when using commandButton

2

The possible reason for this behaviour can be

  1. Areas of the page are being rerendered, but not a page messages component, and an required field is missing or a validation rule is failing. In this scenario the error will be swallowed and the page will remain unchanged.
  2. The form submission is using an action region, which excludes the input from the server side processing.
  3. The form submission component (e.g. commandbutton, actionfunction) has the immediate attribute set to true. This will bypass validation rules but also discard any input from the user.

You can refer this question in SFSE

  • I updated the question, it's not about not rerendering correctly.but about not assigning the updated UI values at the controller – highfive Sep 7 '15 at 18:21
1

Ended up with an alternative. Added actionSupport for inputText fields to be fired in the onchange event. Working as expected.

<apex:inputText id="quantity" value="{!item.quantity}" >
      <apex:actionSupport action="{!calculateTotals}" rerender="pnlSummary" event="onchange"/>       
</apex:inputText>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.