+ Start a Discussion
mauricio.ramos@corpitalmauricio.ramos@corpital 

PageBlockTable row values dissapear after rerender

Hello,

 

Looking for help solving a simple issue that will most likely be a quick fix but yet I've spent too much time trying to crack it. The issue is that I have a pageblocktable with OpportunityLineItems, these can have their fields updated such as Qty and Discount. on the Qty and Discount field's onblur event  I perform an upsert of the OppLine so that the server can calculate the TotalPrice and other relevant fields. Once the save is done, I requery for the record to show the latest updated values from the server, BUT even though in the debug log I see that the record got updated, when I rerender the field (even tried rerendering the entire table) the value simply disappears as if by "magic". 

 

How can I get the row rerendered with the new values in the record??? Please assist! Below is code for controller and VF page where the issue seems to be happening:

 

VF page table: (NOTE: some fields that are static and do not get updated have been removed to downsize post length)

 <apex:outputPanel id="tablePnl">  
        <apex:pageblockTable value="{!OLIs}" var="OLI" id="OLIList" >
            <apex:column id="DelCol"> 
                {!OLI.Id}  -- {!OLI.TotalPrice}                   
                <apex:commandButton value="Delete" action="{!del}" rerender="tablePnl,detailPanel">
                    <apex:param name="delname" value="{!OLI.id}" assignTo="{!currOLIid}"/> 
                </apex:commandButton>          
            </apex:column>                    
            <apex:column headerValue="Quantity"> 
                <apex:inputField value="{!OLI.Quantity}"  id="fQTY" required="{!OLI.PriceBookEntry.Product2.Name != null}"  >
                    <apex:actionSupport event="onblur" rerender="tablePnl,fUnitCost,fProfit,fTotalPrice,fDiscPct,fDiscAmt" action="{!saveOLI}" disabled="{!(OLI.Quantity == null || OLI.Quantity <= 0) || (OLI.UnitPrice == null || OLI.UnitPrice <= 0)}"  >
                        <apex:param name="currOLIQty" value="{!OLI.Id}" assignTo="{!currOLIid}"/>
                    </apex:actionSupport>
                </apex:inputField>
            </apex:column>             
            <apex:column headerValue="Unit Cost" >
                <apex:inputField value="{!OLI.Unit_Cost__c}" id="fUnitCost"/>       
            </apex:column>
            <apex:column headerValue="Sales Price ex VAT"">
                <apex:inputField value="{!OLI.UnitPrice}"/>
            </apex:column>
            <apex:column headerValue="Line Disc Pct.">
                <apex:inputField value="{!OLI.Discount}" id="fDiscPct">
                <apex:actionSupport event="onblur" rerender="fUnitCost,fProfit,fTotalPrice,fDiscPct,fDiscAmt" action="{!saveOLI}" disabled="{!(OLI.Quantity == null || OLI.Quantity <= 0) || (OLI.UnitPrice == null || OLI.UnitPrice <= 0)}"  >
                        <apex:param name="currOLIQty" value="{!OLI.Id}" assignTo="{!currOLIid}"/>
                    </apex:actionSupport>
                </apex:inputField>
            </apex:column>
            <apex:column headerValue="Total Price">
                    <apex:outputField value="{!OLI.TotalPrice}" id="fTotalPrice"  />
            </apex:column>         
        </apex:pageBlockTable>
    </apex:outputPanel>

 And this is the code in the controller that performs the saveOLI action (saving the record):

    public PageReference saveOLI() {
        system.debug('###currOLI: ' + currOLI);
        currOLI.TotalPrice = null;
        try{
        upsert currOLI;
        currOLI = loadOLI(currOLI);
        for(OpportunityLineItem o: OLIs) {
            if(o.id == currOLI.id) {
                o = currOLI;
                system.debug('###After saveOLI OLIs(o) from currOLI: ' + o);
            }
        }
        }catch(Exception e) {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error saving Opportunity Product: ' + e.getMessage());
            ApexPages.addMessage(myMsg);
        }
        return null;
    }

 

Best Answer chosen by Admin (Salesforce Developers) 
asish1989asish1989

Hi 
change render property, You need to write this render = "tablePnl" in the both actionsupport tag, 
invoke that function getOLIs() which was a list function to populate pageblock table data, inside saveOLI() method.

public PageReference saveOLI() {
         getOlis();
        system.debug('###currOLI: ' + currOLI);
        currOLI.TotalPrice = null;
        try{
        upsert currOLI;
        currOLI = loadOLI(currOLI);
        for(OpportunityLineItem o: OLIs) {
            if(o.id == currOLI.id) {
                o = currOLI;
                system.debug('###After saveOLI OLIs(o) from currOLI: ' + o);
            }
        }
        }catch(Exception e) {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error saving Opportunity Product: ' + e.getMessage());
            ApexPages.addMessage(myMsg);
        }
        return null;
    }

 

<apex:actionSupport event="onblur" rerender="tablePnl" action="{!saveOLI}" disabled="{!(OLI.Quantity == null || OLI.Quantity <= 0) || (OLI.UnitPrice == null || OLI.UnitPrice <= 0)}"  >

 

<apex:actionSupport event="onblur" rerender="tabPnl" action="{!saveOLI}" disabled="{!(OLI.Quantity == null || OLI.Quantity <= 0) || (OLI.UnitPrice == null || OLI.UnitPrice <= 0)}"  >

 And let me know , If it works or not,

If this post answers your question , please mark it as solutions so that It can be further referred .

 

    Thanks

All Answers

asish1989asish1989

Hi 
change render property, You need to write this render = "tablePnl" in the both actionsupport tag, 
invoke that function getOLIs() which was a list function to populate pageblock table data, inside saveOLI() method.

public PageReference saveOLI() {
         getOlis();
        system.debug('###currOLI: ' + currOLI);
        currOLI.TotalPrice = null;
        try{
        upsert currOLI;
        currOLI = loadOLI(currOLI);
        for(OpportunityLineItem o: OLIs) {
            if(o.id == currOLI.id) {
                o = currOLI;
                system.debug('###After saveOLI OLIs(o) from currOLI: ' + o);
            }
        }
        }catch(Exception e) {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error saving Opportunity Product: ' + e.getMessage());
            ApexPages.addMessage(myMsg);
        }
        return null;
    }

 

<apex:actionSupport event="onblur" rerender="tablePnl" action="{!saveOLI}" disabled="{!(OLI.Quantity == null || OLI.Quantity <= 0) || (OLI.UnitPrice == null || OLI.UnitPrice <= 0)}"  >

 

<apex:actionSupport event="onblur" rerender="tabPnl" action="{!saveOLI}" disabled="{!(OLI.Quantity == null || OLI.Quantity <= 0) || (OLI.UnitPrice == null || OLI.UnitPrice <= 0)}"  >

 And let me know , If it works or not,

If this post answers your question , please mark it as solutions so that It can be further referred .

 

    Thanks

This was selected as the best answer
mauricio.ramos@corpitalmauricio.ramos@corpital
HELLO I am accepting this as the solution, although I had to make a small tweak: INSTEAD OF JUST RERENDERING tablePanel, I had to add all the other field id names(ftotalPRice, fQuantity, fProfit, etc) ELSE the table was not rerendered, yet with all the IDs in the rerender AND using your suggestion to add the getOLIs to the method it now works wonderfully!! Thank you so much!!!!
HariniHarini

Hi

 

I have the same problem, I am displaying products information in a pageblock table with a few input fields and a check box. On save I am performaing a check where if checkbox ix checked, quantity field must no be 0 which is default value.

 

if(prod.checked == true) {

 if(prod.quantity ==0){
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Please Enter Quantity  for the Product Selected!!') );
                        return null; ----> This return null statement is causing the problem , though I want to be on the same page I wan tto retain the values inputted by user
                     }

 

Can you please share your code or let me know how I can retain the values entered by user and the validation done.

 

Thanks

 

mauricio.ramos@corpitalmauricio.ramos@corpital
Hello, not sure where your problem may be since the code provided is partial BUT is the issue when you show an error on the page given 0 qty but checked? OR is it for saved prods that do not show calculated values. If you insert/update a record then you should requery for the new record so the rerender will show updated values. If your not navigating to another page then always return null, that is correct. Maybe check your vf code or share it so I can get a better perspective in your issue.

Sent from my iPhone 5