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
DRobi83DRobi83 

Apex commandLink action is rerendering default values on fields within layout

Hello

 

I have some working code the way i want it, however when you click the "Add Row" or "Remove Row" command links, all my previously created values (line items) default the drop down fields back from their selection, to a default selection. Essentially, the user loses all their previous selections. Its further worth noting that the 'picklists' are actually lookup values being called from a class


Does anyone have any changes/ideas about the code to make it so the values are set and not 'rerendered' when you click my commandLinks?

 

Thanks in advance, been all day on this!

 

VF

 

<apex:page standardController="Invoice__c" extensions="newInvoiceLineItems,CurrencyPL,TaxPL,ProductPL">
    <apex:form >
    <apex:sectionHeader title="Invoice and Credit Memo" subtitle="{!Invoice__c.Name}"  /> 
    <apex:pageBlock title="Invoice and Credit Memo Detail" >
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" rerender="error" />
                <apex:commandButton value="Cancel" action="{!cancel}" rerender="error" />
            </apex:pageBlockButtons>
            <apex:pageMessages ></apex:pageMessages>
        <apex:pageBlockSection title="Information" columns="2" collapsible="false">
            <apex:inputField value="{!Invoice__c.Customer__c}" required="true" />
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Currency"/>
                <apex:outputPanel layout="block" styleClass="requiredInput" >
                <apex:outputPanel layout="block" styleClass="requiredBlock"/>
                <apex:selectList value="{!Invoice__c.Currency__c}" 
                     required="True" size="1" id="invoicecurr">
                    <apex:selectOptions value="{!getCurrency}"/>
                </apex:selectList>
                </apex:outputPanel>
            </apex:pageBlockSectionItem> 
            <apex:inputField value="{!Invoice__c.Date_Document__c}" required="true" /> 
            <apex:inputField value="{!Invoice__c.Due_Date__c}" required="true" />
            <apex:inputField value="{!Invoice__c.Type__c}" required="true" />  
            
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Description"/>
                <apex:outputPanel layout="block" styleClass="requiredInput" >
                <apex:outputPanel layout="block" styleClass="requiredBlock"/>
                <apex:inputTextarea value="{!Invoice__c.Description__c}" required="true" cols="40" rows="3" /> 
                </apex:outputPanel>
            </apex:pageBlockSectionItem> 
            
        </apex:pageBlockSection>   
            <apex:pageBlockTable value="{!lines}" var="li" id="table">  
                <apex:column headerValue="Line Items" colspan="2">
                    <apex:outputLabel value="Description"/>
                    <apex:inputField value="{!li.Display_Name__c}" required="true"/>
                    <apex:outputLabel value="Amount inc Tax"/>
                    <apex:inputField value="{!li.Amount_Inc_Tax__c}" required="true"/>
                    <apex:outputLabel value="Invoice"/>
                    <apex:inputField value="{!li.Invoice__c}"/>
                    
               <apex:outputLabel value="Currency"/>
                        <apex:outputPanel layout="block" styleClass="requiredInput" >
                        <apex:outputPanel layout="block" styleClass="requiredBlock"/>
                            <apex:selectList value="{!li.Currency__c}" required="True" size="1">
                    <apex:selectOptions value="{!getCurrency}"/>
                </apex:selectList>
                </apex:outputPanel>

               <apex:outputLabel value="Product"/>
                        <apex:outputPanel layout="block" styleClass="requiredInput" >
                        <apex:outputPanel layout="block" styleClass="requiredBlock"/>
                            <apex:selectList value="{!li.Product_For_Sale__c}" required="True" size="1">
                    <apex:selectOptions value="{!getProduct}"/>
                </apex:selectList>
                </apex:outputPanel>
                
               <apex:outputLabel value="Tax"/>
                        <apex:outputPanel layout="block" styleClass="requiredInput" >
                        <apex:outputPanel layout="block" styleClass="requiredBlock"/>
                            <apex:selectList value="{!li.Tax__c}" required="True" size="1">
                    <apex:selectOptions value="{!getTax}"/>
                </apex:selectList>
                </apex:outputPanel>                
                    
                    <apex:outputLabel value="Quantity"/>
                    <apex:inputField value="{!li.Quantity__c}" required="true"/>
                                                       
                    <apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error" immediate="true" />&nbsp;|&nbsp;&nbsp;
                    <apex:commandLink value="Remove Row" action="{!removeRow}" rerender="table,error" immediate="true" />
                 </apex:column>    
            </apex:pageBlockTable>   
              
    </apex:pageBlock>
    </apex:form>
</apex:page>

  classes

 

public class newInvoiceLineItems {

    public List<miiFinance__Invoice_Line_Item__c> lines {get; set;}
    private final miiFinance__Invoice__c parInv;
    public newInvoiceLineItems(ApexPages.StandardController myController) {
        parInv=(miiFinance__Invoice__c)myController.getrecord();
        lines = new List<miiFinance__Invoice_Line_Item__c>();
        miiFinance__Invoice_Line_Item__c LitOrd = new miiFinance__Invoice_Line_Item__c();
        LitOrd.miiFinance__Invoice__c = parInv.id;
        lines.add(LitOrd);}

    public void addrow() {
        miiFinance__Invoice_Line_Item__c LitOrd = new miiFinance__Invoice_Line_Item__c();
        LitOrd.miiFinance__Invoice__c = parInv.id;
        lines.add(LitOrd);}
            
    public void removerow(){
        Integer i = lines.size();
        lines.remove(i-1);}
            
    public PageReference save() {
        insert lines;
        PageReference home = new PageReference('/home/home.jsp');
        home.setRedirect(true);
        return home; }}

 

class which looksup values of picklist

 

public class ProductPL {
    private miiFinance__Invoice__c invoice;
    public ProductPL(ApexPages.StandardController controller) {
    this.invoice = (miiFinance__Invoice__c)controller.getRecord();
    }
    public List <SelectOption> getProduct {
    Get{
    List <SelectOption> product = new List <SelectOption>();
    for( miiFinance__Product_For_Sale__c pr: [select Name, miiFinance__Display_Name__c from miiFinance__Product_For_Sale__c])
    product.add(new selectOption(pr.id, pr.Name + ' - ' +  pr.miiFinance__Display_Name__c));
    return product;
    }
    Set;
    }
    }

 

 

bob_buzzardbob_buzzard

You have the immediate attribute set to true on your command links - this indicates all user changes should be discarded and the page refreshed with the original values.  Remove that attribute and you should be good to go.